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

Directives Introduction

Learn how Angular directives extend HTML and control the behavior, appearance, and structure of elements.

What are Directives?

Directives are special Angular features that allow you to add behavior to HTML elements or change the structure of the DOM.

Angular provides built-in directives and also allows developers to create custom directives.

Directive Flow

1
HTML Element

Start with an HTML element in the template.

→
2
Directive

Apply an Angular directive to the element.

→
3
Angular

Angular processes the directive.

→
4
UI Behavior

The element behavior or structure changes.

Types of Directives

A
Attribute Directives

Change the appearance or behavior of an existing HTML element.

ngClass
ngStyle
S
Structural Directives

Change the structure of the DOM by adding or removing elements.

*ngIf
*ngFor
C
Custom Directives

Developer-created directives used to implement application-specific behavior.

ng generate directive

Attribute Directive Example

Attribute directives modify the behavior or appearance of an existing element.

HTML
<div [ngClass]="{ active: isActive }">
    Student Profile
</div>
Result:
The active class is applied when isActive is true.

Structural Directive Example

Structural directives control whether elements are created or displayed in the DOM.

HTML
<div *ngIf="isLoggedIn">
    Welcome to CIIT Training Institute
</div>
Result:
The element is displayed only when isLoggedIn is true.

Custom Directive

Angular allows developers to create their own directives for reusable behavior.

CLI Command
ng generate directive highlight
HTML
<p appHighlight>
    Angular Training
</p>
Result:
The custom appHighlight directive can add reusable behavior to the paragraph.

Directive Comparison

Type Purpose Example
Attribute Changes appearance or behavior ngClass
Structural Changes DOM structure *ngIf
Custom Provides application-specific behavior appHighlight

Complete Example

Component
export class StudentComponent {

    isActive = true;

    isLoggedIn = true;

}
Template
<div [ngClass]="{ active: isActive }">

    <h3>Student Profile</h3>

    <div *ngIf="isLoggedIn">
        Welcome to Angular Training
    </div>

</div>

Student Profile

Welcome to Angular Training

Why Use Directives?

R
Reusable

Directive behavior can be reused across components.

U
UI Control

Directives help control element behavior and appearance.

D
DOM Control

Structural directives can control DOM elements.

C
Custom Behavior

Developers can create directives for specific needs.

Best Practices

  • Use directives when behavior needs to be reused.
  • Keep custom directive logic simple and focused.
  • Use meaningful directive names.
  • Prefer built-in Angular directives when they solve the requirement.
  • Avoid putting unnecessary business logic inside directives.
  • Keep DOM-related behavior encapsulated inside directives.

Summary

  • Directives extend HTML with Angular behavior.
  • Attribute directives change appearance or behavior.
  • Structural directives change the DOM structure.
  • Custom directives provide reusable application-specific behavior.
  • Directives make Angular templates more powerful and reusable.