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

Attribute Directives

Learn how Angular attribute directives change the appearance or behavior of existing HTML elements.

What are Attribute Directives?

Attribute directives are Angular directives that modify the behavior, appearance, or properties of an existing HTML element.

Unlike structural directives, attribute directives do not create or remove elements from the DOM.

Attribute Directive Flow

1
HTML Element

Create an element in the Angular template.

→
2
Directive

Apply an attribute directive to the element.

→
3
Angular

Angular evaluates the directive and its values.

→
4
UI Update

The appearance or behavior changes.

Common Attribute Directives

C
ngClass

Dynamically adds or removes CSS classes.

S
ngStyle

Dynamically applies CSS styles.

A
Attribute Binding

Dynamically changes HTML attributes.

C
Custom Directive

Adds reusable custom behavior to elements.

ngClass Directive

The ngClass directive allows CSS classes to be added or removed dynamically.

Component
isActive = true;
isPremium = false;
HTML
<div [ngClass]="{
    active: isActive,
    premium: isPremium
}">
    Student Profile
</div>
Result:
The active class is applied because isActive is true.

ngClass with Multiple Classes

Multiple CSS classes can be controlled using an object.

HTML
<div [ngClass]="{
    active: isActive,
    premium: isPremium,
    highlighted: isHighlighted
}">

    Student Details

</div>
Result:
Each class is applied according to its corresponding boolean value.

ngStyle Directive

The ngStyle directive dynamically applies one or more CSS styles to an element.

Component
textColor = 'purple';
fontSize = 20;
HTML
<p [ngStyle]="{
    color: textColor,
    'font-size.px': fontSize
}">

    Angular Full Stack Training

</p>
Result:
The text color and font size are controlled dynamically.

Attribute Binding

Angular can dynamically change HTML attributes using attribute binding.

HTML
<button
    [attr.disabled]="isDisabled ? true : null">

    Submit

</button>
Result:
The disabled attribute is added when isDisabled is true.

ngClass vs ngStyle

Directive Purpose Example
ngClass Apply CSS classes dynamically [ngClass]="classes"
ngStyle Apply CSS styles dynamically [ngStyle]="styles"
attr Change HTML attributes [attr.title]="title"

Complete Student Example

student.component.ts
export class StudentComponent {

    studentName = 'Pradnya';

    isActive = true;

    isPremium = true;

    textColor = 'purple';

    fontSize = 20;

}
student.component.html
<div
    [ngClass]="{
        active: isActive,
        premium: isPremium
    }"
    [ngStyle]="{
        color: textColor,
        'font-size.px': fontSize
    }">

    <h3>{{studentName}}</h3>

    <p>Angular Full Stack Student</p>

</div>

Pradnya

Angular Full Stack Student

Benefits of Attribute Directives

R
Reusable

Directive behavior can be reused across multiple elements.

D
Dynamic

UI appearance can change according to component data.

U
UI Control

Control classes, styles, and attributes dynamically.

C
Customizable

Developers can create their own attribute directives.

Best Practices

  • Use ngClass for dynamic CSS classes.
  • Use ngStyle for dynamic style values.
  • Prefer class-based styling for reusable UI designs.
  • Keep directive expressions simple and readable.
  • Use meaningful class and directive names.
  • Create custom directives only when reusable behavior is required.

Summary

  • Attribute directives modify existing HTML elements.
  • ngClass dynamically manages CSS classes.
  • ngStyle dynamically manages CSS styles.
  • Attribute binding can dynamically control HTML attributes.
  • Attribute directives do not change the DOM structure.
  • Custom directives can provide reusable application behavior.