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 Syntax

Angular Template Syntax provides special syntax that allows HTML templates to display component data, bind properties, handle events, and create interactive user interfaces.

What is Template Syntax?

Template syntax is the collection of Angular features that can be used inside an HTML template.

It connects the component class with the user interface and allows the UI to react to application data and user actions.

Simple Definition

Angular Template Syntax makes normal HTML dynamic and interactive.

Template Syntax Flow

Component Data & Methods
→
Template Syntax Angular Expressions
→
Angular Processes Binding
→
Browser Interactive UI

Main Angular Template Syntax

Interpolation

Displays component data in the template.

{{ name }}
Property Binding

Binds a component value to an element property.

[value]="name"
Event Binding

Responds to user events.

(click)="save()"
Two-Way Binding

Synchronizes data between input and component.

[(ngModel)]="name"

1. Interpolation

Interpolation uses double curly braces to display values from the component class.

Component
export class StudentComponent {

    studentName = 'Sam';

}
Template
<h2>Student Name: {{ studentName }}</h2>
Expected Output:

Student Name: Sam

2. Property Binding

Property binding connects a component property to a property of an HTML element or Angular component.

Component
export class StudentComponent {

    imageUrl = 'assets/student.jpg';

}
Template
<img [src]="imageUrl" alt="Student">
Component imageUrl
→
Binding [src]
→
HTML Image

3. Event Binding

Event binding allows a template to respond to user actions such as button clicks.

Component
export class StudentComponent {

    message = '';

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

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

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

After clicking the button, the message Welcome Pradnya! appears.

4. Two-Way Binding

Two-way binding allows data to move between the component and the input element.

Example
export class StudentComponent {

    studentName = '';

}
Template
<input
    [(ngModel)]="studentName"
    placeholder="Enter student name">

<p>Student Name: {{ studentName }}</p>
Component studentName
↔
[(ngModel)] Two-Way Binding
↔
Input User Data

5. Attribute Binding

Attribute binding can be used when you need to bind an HTML attribute rather than a DOM property.

Example
studentId = 101;
Template
<div [attr.data-student-id]="studentId">
    Student Information
</div>

6. Class Binding

Class binding allows CSS classes to be added or removed based on component data.

Component
isActive = true;
Template
<div [class.active]="isActive">
    Student Status
</div>
Expected Result:
Student Status

7. Style Binding

Style binding allows individual CSS style properties to be controlled using component values.

Component
fontSize = 20;
Template
<p [style.font-size.px]="fontSize">
    Angular Student
</p>
Expected Output:
Angular Student

8. Template Reference Variable

A template reference variable gives a convenient reference to an element or directive instance within the template.

Example
<input #studentInput placeholder="Enter name">

<button (click)="showName(studentInput.value)">
    Show Name
</button>
How it works

#studentInput creates a reference to the input element, allowing the template to access its current value.

9. Template Expressions

Angular template expressions can evaluate values and simple expressions.

Example
marks = 85;
total = 100;
Template
<p>
    Percentage:
    {{ (marks / total) * 100 }}%
</p>
Expected Output:
Percentage: 85%

10. Event Object

Event handlers can receive the browser event object when required.

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

    console.log(event);

}

11. Control Flow in Templates

Modern Angular templates support control-flow syntax for conditional rendering and repeated content.

Conditional Rendering
@if (isLoggedIn) {
    <p>Welcome Sam</p>
}
Repeated Content
@for (student of students; track student) {
    <p>{{ student }}</p>
}

Template Syntax Quick Reference

Syntax Purpose Example
Interpolation Display component data {{ name }}
Property Binding Bind element property [value]="name"
Event Binding Handle user events (click)="save()"
Two-Way Binding Synchronize data [(ngModel)]="name"
Attribute Binding Bind HTML attributes [attr.id]="studentId"
Class Binding Control CSS classes [class.active]="isActive"
Style Binding Control CSS styles [style.font-size.px]="size"
Reference Variable Reference template element #studentInput

Complete Template Syntax Example

student.component.ts
export class StudentComponent {

    studentName = 'Sam';
    course = 'Angular Full Stack';
    isActive = true;

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

}
student.component.html
<div [class.active]="isActive">

    <h2>Student Profile</h2>

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

    <p>
        Course: {{ course }}
    </p>

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

</div>
Expected Output:

Student Profile

Name: Sam

Course: Angular Full Stack

Template Syntax Best Practices

  • Keep template expressions simple.
  • Use property binding instead of manually changing DOM properties.
  • Use event binding for user interactions.
  • Avoid complex business logic inside templates.
  • Use reusable components when templates become too large.
  • Keep binding names meaningful and easy to understand.

Summary

Angular Template Syntax connects component data and logic with the HTML user interface.

Important syntax includes Interpolation, Property Binding, Event Binding, Two-Way Binding, Class Binding, Style Binding and Template Reference Variables.

Understanding template syntax is essential for creating dynamic and interactive Angular applications.