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

Parent-Child Components

Angular applications are built using reusable components. A parent component can contain one or more child components and can communicate with them using component inputs and outputs.

What are Parent-Child Components?

A parent component is a component that contains another component inside its template.

The component placed inside the parent template is called the child component.

Simple Example

Suppose StudentComponent is the parent and StudentDetailsComponent is the child. The parent can send student information to the child.

Parent-Child Component Structure

Parent Component StudentComponent
Child Component StudentDetailsComponent
Child Component StudentCourseComponent

Parent-Child Communication

Angular commonly uses two directions of communication:

Parent → Child

The parent sends data to the child using an input property.

@Input
Child → Parent

The child sends events or data back to the parent using an output property.

@Output

Parent to Child Communication

The parent component can pass data to a child component using @Input.

Parent studentName = "Sam"
↓
@Input Receives studentName
↓
Child Displays Student Name

Step 1: Create Parent Component

student.component.ts
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    standalone: true,
    templateUrl: './student.component.html'
})
export class StudentComponent {

    studentName = 'Sam';

}

Step 2: Use Child Component in Parent

The child component selector is placed inside the parent template.

student.component.html
<h2>Student Information</h2>

<app-student-details
    [name]="studentName">
</app-student-details>

Here the parent sends the value of studentName to the child's name input.

Step 3: Create Child Component

student-details.component.ts
import { Component, Input } from '@angular/core';

@Component({
    selector: 'app-student-details',
    standalone: true,
    template: `
        <h3>Student Details</h3>
        <p>Student Name: {{ name }}</p>
    `
})
export class StudentDetailsComponent {

    @Input() name = '';

}
Expected Output:

Student Details

Student Name: Sam

Using Input

The input property receives a value from the parent component.

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

@Component({
    selector: 'app-student-details',
    standalone: true,
    template: `
        <p>Student: {{ name }}</p>
    `
})
export class StudentDetailsComponent {

    @Input() name = '';

}
Parent studentName = "Sam"
→
Property Binding [name]
→
Child @Input() name

Child to Parent Communication

A child component can communicate with its parent using @Output and an event emitter.

Child User Action
↑
@Output EventEmitter
↑
Parent Handles Event

Child to Parent Example

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

@Component({
    selector: 'app-student-details',
    standalone: true,
    template: `
        <button (click)="sendMessage()">
            Send Message
        </button>
    `
})
export class StudentDetailsComponent {

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

    sendMessage() {
        this.message.emit('Hello Parent');
    }

}

The parent listens to the event from the child.

Parent Template
<app-student-details
    (message)="receiveMessage($event)">
</app-student-details>

Complete Parent-Child Example

Parent Component
import { Component } from '@angular/core';
import { StudentDetailsComponent }
from './student-details.component';

@Component({
    selector: 'app-student',
    standalone: true,
    imports: [StudentDetailsComponent],
    template: `
        <h2>Student Profile</h2>

        <app-student-details
            [name]="studentName">
        </app-student-details>
    `
})
export class StudentComponent {

    studentName = 'Pradnya';

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

@Component({
    selector: 'app-student-details',
    standalone: true,
    template: `
        <div class="student-details">
            <h3>Student Details</h3>
            <p>Name: {{ name }}</p>
        </div>
    `
})
export class StudentDetailsComponent {

    @Input() name = '';

}
Expected Output:

Student Profile

Student Details

Name: Pradnya

Parent-Child Communication Summary

Direction Angular Feature Purpose
Parent → Child @Input Pass data to child.
Child → Parent @Output Send events to parent.
Child → Parent EventEmitter Emit custom events.
Parent → Child Property Binding Bind parent values to child inputs.

Benefits of Parent-Child Components

Reusability

Child components can be reused in different parent components.

Communication

Components can exchange data and events.

Organization

Large interfaces can be divided into smaller components.

Maintenance

Smaller components are easier to test and maintain.

Best Practices

  • Keep parent components responsible for overall page-level data.
  • Use inputs to pass data from parent to child.
  • Use outputs to communicate child events to the parent.
  • Keep child components focused on a specific responsibility.
  • Avoid unnecessary communication between deeply nested components.
  • Use reusable child components for repeated UI functionality.

Summary

Parent-child components allow Angular applications to divide a large interface into smaller and reusable components.

@Input is commonly used to pass data from a parent to a child, while @Output with EventEmitter is used for child-to-parent events.

Understanding component communication is essential for building organized and reusable Angular applications.