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

Reusable Components

Reusable Components are Angular components designed to be used multiple times in different parts of an application. They help reduce duplicate code and make applications easier to maintain.

What is a Reusable Component?

A reusable component is a component created for a common UI or functionality that can be used in multiple places.

Instead of writing the same HTML and logic repeatedly, we create one component and reuse it whenever required.

Simple Example

A Student Card can be created once and reused for Sam, Pradnya and other students by passing different data.

Reusable Component Flow

Create Once StudentCardComponent
→
Use for Sam Student Data
→
Use for Pradnya Student Data
→
Reuse Anywhere Multiple Pages

Why Use Reusable Components?

Reuse

The same component can be used multiple times.

Less Code

Avoid writing the same UI code repeatedly.

Easy Maintenance

Changes can be made in one component.

Consistency

Reused components provide consistent UI.

Creating a Reusable Student Card

Suppose we want to display student information in the same card design throughout our Angular application.

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

@Component({
    selector: 'app-student-card',
    standalone: true,
    template: `
        <div class="student-card">
            <h3>{{ name }}</h3>
            <p>Course: {{ course }}</p>
        </div>
    `
})
export class StudentCardComponent {

    @Input() name = '';
    @Input() course = '';

}

Using the Reusable Component

The same component can now be used multiple times with different input values.

app.component.html
<app-student-card
    name="Sam"
    course="Angular Full Stack">
</app-student-card>

<app-student-card
    name="Pradnya"
    course="Java Full Stack">
</app-student-card>
Expected Output:

Sam

Course: Angular Full Stack

Pradnya

Course: Java Full Stack

Reusable Component with Property Binding

Input values can also come from properties of the parent component.

Parent Component
export class AppComponent {

    studentName = 'Sam';
    studentCourse = 'Angular Full Stack';

}
Parent Template
<app-student-card
    [name]="studentName"
    [course]="studentCourse">
</app-student-card>
Expected Output:

Sam

Course: Angular Full Stack

Using One Component Multiple Times

A reusable component can appear many times on the same page.

Multiple Component Instances
<app-student-card
    name="Sam"
    course="Angular">
</app-student-card>

<app-student-card
    name="Pradnya"
    course="React">
</app-student-card>

<app-student-card
    name="Samiksha"
    course=".NET Full Stack">
</app-student-card>
Expected Output:

Sam

Course: Angular

Pradnya

Course: React

Samiksha

Course: .NET Full Stack

Example: Reusable Button Component

Reusability is not limited to student cards. Buttons, navigation items, alerts and other UI elements can also be created as reusable components.

reusable-button.component.ts
import { Component, Input, Output, EventEmitter }
from '@angular/core';

@Component({
    selector: 'app-button',
    standalone: true,
    template: `
        <button (click)="clicked.emit()">
            {{ label }}
        </button>
    `
})
export class ButtonComponent {

    @Input() label = 'Click';
    @Output() clicked = new EventEmitter<void>();

}
Using the Button
<app-button
    label="Save Student"
    (clicked)="saveStudent()">
</app-button>

Reusable Component Architecture

Reusable Component Student Card
↓
Page 1 Student List
Page 2 Dashboard
Page 3 Profile

Common Reusable Components

Student Card

Displays student information.

Form Control

Reusable input or form elements.

Notification

Displays application messages.

Button

Reusable action button.

Reusable Component Design

1 Identify Repeated UI Find duplicate code
→
2 Create Component Move common logic
→
3 Add Inputs Accept dynamic data
→
4 Reuse Use across pages

Advantages of Reusable Components

  • Code Reusability: Write common functionality once and reuse it.
  • Consistency: The same component provides a consistent design.
  • Maintainability: Changes can be made in a single component.
  • Scalability: Large applications can be built using smaller components.
  • Testing: Small components are easier to test independently.

Best Practices

  • Keep reusable components focused on one responsibility.
  • Use @Input for dynamic data instead of hard-coding values.
  • Use @Output when the reusable component needs to notify its parent.
  • Give reusable components clear and meaningful names.
  • Avoid putting unrelated business logic inside UI components.
  • Keep reusable components independent whenever practical.

Summary

Reusable Components allow developers to create a component once and use it multiple times throughout an Angular application.

Inputs such as @Input can be used to provide different data to each component instance, while @Output can be used to communicate events back to the parent.

Reusable components reduce duplicate code, improve consistency, simplify maintenance and make Angular applications easier to scale.