Master Angular From Scratch

Learn Angular with clear, interactive, and structured lessons for beginners and developers.

ANGULAR COURSE SYLLABUS
1. Angular Introduction
Angular Introduction Angular History Angular Fundamentals Angular Architecture Component-Based Angular
2. Angular Setup
Angular Setup Introduction Installing Node.js Installing Angular CLI Creating an Angular Application Angular Project Structure
3. Components
Components Overview Component Anatomy Creating Components Component Selector Component Template Component Styles Component Metadata Standalone Components Parent and Child Components Reusable Components
4. Templates
Templates Introduction Template Syntax Template Expressions Template Statements Template Reference Variables ng-template ng-container ngTemplateOutlet Built-in Control Flow
5. Data Binding
Data Binding Introduction Interpolation Binding Property Binding Event Binding Two-Way Data Binding Class & Style Binding
6. Directives
Directives Introduction Attribute Directives Structural Directives Custom Directives
7. Pipes
Pipes Introduction Built-in Pipes Parameterized Pipes Chaining Pipes Custom Pipes
8. Event Handling
Event Handling Introduction DOM Events Event Binding Syntax Event Object Passing Data to Event Handlers
9. Input & Output
Component Communication @Input @Output EventEmitter
10. Lifecycle Hooks
Lifecycle Hooks Introduction ngOnInit ngOnChanges ngAfterViewInit ngOnDestroy
11. Services
Services Introduction Creating Angular Services Using Services in Components Sharing Data Through Services Service Scope
12. Dependency Injection
Dependency Injection Introduction Injecting Dependencies InjectionToken Provider Configuration
13. Routing
Routing Introduction Route Configuration RouterLink & Navigation Route Parameters Child Routes Route Guards
14. Forms
Angular Forms Introduction Template-Driven Forms Reactive Forms Form Validation Form Submission & Error Handling
15. HttpClient
HttpClient Introduction Configuring HttpClient GET Request POST, PUT & DELETE Requests Headers & Parameters HTTP Error Handling
16. Observables
Observables Introduction Creating & Subscribing to Observables Observable Data Streams Observable Operators Subscription Management
17. RxJS
RxJS Introduction RxJS Operators Transformation & Filtering Combining Observables Higher-Order Mapping Subjects
18. API Integration
API Integration Introduction Connecting Angular with REST API Consuming API Data CRUD API Integration API Response & Error Handling

Angular EventEmitter

Learn how EventEmitter works with @Output to send events and data from a child component to a parent component in Angular.

What is EventEmitter?

In Angular, EventEmitter is used with @Output to create custom events in a child component.

The child component can use the emit() method to send information to its parent component.

This provides a clear communication flow from Child → Parent.

EventEmitter Communication Flow

Child Component User Action
→
EventEmitter emit()
→
Parent Component $event

Basic EventEmitter Syntax

Import EventEmitter
import { Component, Output, EventEmitter } from '@angular/core';
Create EventEmitter
@Output() courseSelected =
    new EventEmitter<string>();
Emit Event
this.courseSelected.emit('Java Full Stack');

How EventEmitter Works

1
Create Event

Create a custom event using @Output and EventEmitter.

2
User Action

A button click or another action triggers the event.

3
Emit Data

The emit() method sends the event and optional data.

4
Parent Receives

The parent receives the emitted value using $event.

Simple EventEmitter Example

Child Component
import {
    Component,
    Output,
    EventEmitter
} from '@angular/core';

@Component({
    selector: 'app-course-card',
    templateUrl: './course-card.component.html'
})
export class CourseCardComponent {

    @Output() courseSelected =
        new EventEmitter<string>();

    selectCourse() {

        this.courseSelected.emit('Python Full Stack');

    }

}
Child HTML
<button
    type="button"
    (click)="selectCourse()">

    Select Course

</button>
Parent HTML
<app-course-card
    (courseSelected)="receiveCourse($event)">
</app-course-card>
Parent Component
receiveCourse(course: string) {

    console.log('Selected Course:', course);

}

Output

Python Full Stack

Course selected successfully at CIIT Training Institute.

Using emit()

The emit() method is used to trigger an EventEmitter event.

It can send a value from the child component to the parent component.

Emit Without Data
@Output() enquiry =
    new EventEmitter<void>();

sendEnquiry() {

    this.enquiry.emit();

}
Emit With Data
@Output() courseSelected =
    new EventEmitter<string>();

selectCourse() {

    this.courseSelected.emit('Full Stack .NET');

}

EventEmitter with Event Binding

The parent component listens to the custom event using Angular event binding.

Parent Template
<app-course-card
    (courseSelected)="receiveCourse($event)">
</app-course-card>
Child Action Button Click
→
emit() Event Trigger
→
(courseSelected) Event Binding
→
$event Received Value

EventEmitter with Different Data Types

String
@Output() course =
    new EventEmitter<string>();

this.course.emit('Java Full Stack');
Number
@Output() fees =
    new EventEmitter<number>();

this.fees.emit(35000);
Boolean
@Output() availability =
    new EventEmitter<boolean>();

this.availability.emit(true);
Object
@Output() courseDetails =
    new EventEmitter<object>();

this.courseDetails.emit({
    name: 'Python Full Stack',
    duration: '6 Months',
    mode: 'Online'
});

Complete CIIT Training Institute Example

Suppose CIIT Training Institute has a reusable course card. When a visitor clicks the Enquire Now button, the child component sends the selected course information to the parent component.

EventEmitter handles this Child → Parent communication.

Child Component
import {
    Component,
    Output,
    EventEmitter
} from '@angular/core';

@Component({
    selector: 'app-course-card',
    templateUrl: './course-card.component.html'
})
export class CourseCardComponent {

    @Output() enquiry =
        new EventEmitter<string>();

    courseName = 'Full Stack .NET';

    sendEnquiry() {

        this.enquiry.emit(this.courseName);

    }

}
Child Template
<div class="course-card">

    <h3>{{ courseName }}</h3>

    <p>
        Learn Full Stack Development
        at CIIT Training Institute.
    </p>

    <button
        type="button"
        (click)="sendEnquiry()">

        Enquire Now

    </button>

</div>
Parent Template
<app-course-card
    (enquiry)="receiveEnquiry($event)">
</app-course-card>
Parent Component
receiveEnquiry(course: string) {

    console.log(
        'Enquiry received for:',
        course
    );

}

Event Flow

Enquire Now User Action
→
sendEnquiry() Child Method
→
emit() EventEmitter
→
$event Parent Receives Data

Important Points

1. Event Creation

EventEmitter is generally used with @Output to create custom events.

2. emit() Method

The emit() method triggers the custom event.

3. Send Data

Data can be passed as an argument to emit().

4. Parent Receives Data

The parent accesses emitted data through $event.

EventEmitter Best Practices

  • Use meaningful custom event names.
  • Use EventEmitter with @Output for Child → Parent communication.
  • Use emit() only when the required event occurs.
  • Use appropriate TypeScript types for emitted values.
  • Send only the required information to the parent.
  • Keep communication between components simple and clear.

Summary

EventEmitter is used with Angular @Output to create custom events. The child component uses emit() to send an event or data, while the parent listens to the event using event binding and receives the value through $event.