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 @Output

Learn how to use @Output to send data from a child component to a parent component in Angular.

What is @Output?

In Angular, @Output is used when a child component needs to send information or notify an event to its parent component.

The child component creates a custom event using EventEmitter, while the parent component listens to that event using event binding.

This creates a simple and controlled way for components to communicate from Child → Parent.

Child to Parent Communication

Child Component Generates Event
→
EventEmitter emit()
→
Parent Component Receives Event

Basic @Output Syntax

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>();

}
Emitting Event
selectCourse() {

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

}
Parent Component
<app-course-card
    (courseSelected)="handleCourseSelection($event)">
</app-course-card>

How @Output Works

1
Create Output

The child component creates an event using @Output and EventEmitter.

2
Trigger Event

The child calls emit() when the required action occurs.

3
Parent Listens

The parent listens to the custom event using event binding.

4
Receive Data

The parent receives the emitted value through $event.

Simple @Output 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 Event Binding with @Output

Parent components use the (event) syntax to listen for a custom event generated by the child component.

Event Binding
<app-course-card
    (courseSelected)="receiveCourse($event)">
</app-course-card>
Child Action Course Selection
→
emit() EventEmitter
→
(courseSelected) Event Binding
→
$event Parent Data

Using EventEmitter

EventEmitter is used with @Output to create custom events that can be handled by the parent component.

The emit() method triggers the event and can send data along with the event.

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

sendEnquiry() {

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

}

Complete CIIT Training Institute Example

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

This communication is handled using @Output and EventEmitter.

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 HTML
<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 HTML
<app-course-card
    (enquiry)="receiveEnquiry($event)">
</app-course-card>
Parent Component
receiveEnquiry(course: string) {

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

}

Data Flow

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

Passing Different Types of Data

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

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

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

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

@Input vs @Output

Feature @Input @Output
Direction Parent → Child Child → Parent
Purpose Receive data Send event/data
Main Feature Input Property EventEmitter
Binding [property] (event)
Example [courseName] (courseSelected)

Important Points

1. Child → Parent

@Output is mainly used for passing events or data from a child component to a parent component.

2. Use EventEmitter

EventEmitter is used to create and emit custom events.

3. Use emit()

The emit() method triggers the event and sends the required value.

4. Use $event

The parent component can access the emitted value using $event.

@Output Best Practices

  • Use @Output for Child → Parent communication.
  • Use meaningful custom event names.
  • Use EventEmitter for custom events.
  • Use emit() when the required action occurs.
  • Send only the required data to the parent.
  • Keep child components reusable and focused.

Summary

Angular @Output allows a child component to communicate with its parent component. The child creates a custom event using EventEmitter, sends data using emit(), and the parent listens to that event using event binding and receives the value through $event.