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

Template Statements

Angular Template Statements are used inside event bindings to execute actions when users interact with the application.

What are Template Statements?

Template statements are instructions written inside an Angular template that are executed in response to user actions such as button clicks, input events, mouse events, and keyboard events.

They are commonly used with Angular event binding to call methods or update component data.

Simple Definition

Angular Template Statements tell Angular what action should happen when a user interacts with the UI.

Template Statement Flow

User Performs Action
→
Event Click / Input
→
Statement Executes Action
→
UI Updated Result

Common Template Statements

Method Call

Calls a component method.

(click)="showMessage()"
Property Update

Updates component data.

(click)="count = count + 1"
Event Data

Uses data from an event.

(input)="name = $event.target.value"
Multiple Actions

Executes more than one simple action.

(click)="save(); reset()"

1. Template Statement with Event Binding

The most common use of a template statement is inside event binding. Angular executes the statement when the specified event occurs.

Component
export class StudentComponent {

    message = '';

    showMessage() {
        this.message = 'Welcome Pradnya!';
    }

}
Template
<button (click)="showMessage()">
    Show Message
</button>

<p>
    {{ message }}
</p>
Expected Behavior:

Click the button and Welcome Pradnya! appears.

2. Updating a Property

A template statement can update a component property in response to an event.

Component
export class StudentComponent {

    count = 0;

}
Template
<button (click)="count = count + 1">
    Increase Count
</button>

<p>
    Count: {{ count }}
</p>
Expected Behavior:

Initially: Count: 0

After clicking the button: Count: 1

3. Using the Event Object

Template statements can pass the Angular event object to a component method using $event.

Template
<button (click)="handleClick($event)">
    Click Me
</button>
Component
handleClick(event: Event) {

    console.log(event);

}
How it works

The $event object contains information about the event that occurred in the browser.

4. Handling Input Events

Template statements can be used with input events to update component data as the user types.

Component
export class StudentComponent {

    studentName = '';

}
Template
<input
    (input)="studentName = $event.target.value"
    placeholder="Enter student name">

<p>
    Student Name: {{ studentName }}
</p>
Expected Behavior:

If the user enters Sam, the UI displays:

Student Name: Sam

5. Calling a Method with Parameters

A template statement can call a component method and pass parameters to it.

Component
export class StudentComponent {

    message = '';

    showStudent(name: string) {
        this.message = 'Welcome ' + name;
    }

}
Template
<button (click)="showStudent('Sam')">
    Show Student
</button>

<p>
    {{ message }}
</p>
Expected Output:

Welcome Sam

6. Executing Multiple Actions

A template statement can contain multiple simple actions separated by semicolons when required.

Component
export class StudentComponent {

    message = '';
    count = 0;

    save() {
        this.message = 'Student Saved';
    }

    reset() {
        this.count = 0;
    }

}
Template
<button (click)="save(); reset()">
    Save Student
</button>
Best Practice

Multiple actions should remain simple. If the event handling becomes complicated, move the logic into a component method.

Template Expressions vs Template Statements

Feature Template Expression Template Statement
Purpose Evaluate a value Perform an action
Common Usage Interpolation / Binding Event Binding
Example {{ marks + bonus }} (click)="save()"
Result Produces a value Performs an action

Template Statement Examples

Method Call
(click)="save()"
Property Update
(click)="count = count + 1"
Event Object
(click)="handleClick($event)"
Method Parameter
(click)="showStudent('Sam')"

Complete Template Statement Example

student.component.ts
export class StudentComponent {

    studentName = 'Sam';
    message = '';
    count = 0;

    showMessage() {
        this.message = 'Welcome ' + this.studentName;
    }

    increaseCount() {
        this.count++;
    }

}
student.component.html
<h2>
    Student Profile
</h2>

<p>
    Name: {{ studentName }}
</p>

<button (click)="showMessage()">
    Show Welcome Message
</button>

<p>
    {{ message }}
</p>

<button (click)="increaseCount()">
    Increase Count
</button>

<p>
    Count: {{ count }}
</p>
Expected Output:

Student Profile

Name: Sam

Welcome Sam

Count: 1

Template Statement Best Practices

  • Use template statements mainly with event binding.
  • Keep event statements short and readable.
  • Use component methods for complex operations.
  • Use $event when event information is required.
  • Avoid putting large business logic directly inside templates.
  • Use meaningful method names such as saveStudent() or showMessage().

Summary

Angular Template Statements are used to execute actions in response to user events and interactions.

Common uses include Method Calls, Property Updates, Event Objects, Method Parameters and Multiple Simple Actions.

Template statements are mainly used with Event Binding and should remain simple and readable.