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

Angular Component Template

A component template defines the user interface of an Angular component. It contains HTML along with Angular template syntax used to display and interact with application data.

What is a Component Template?

A component template is an HTML file associated with an Angular component. It defines what should be displayed in the browser.

Angular extends normal HTML with features such as interpolation, property binding, event binding, directives and control flow.

Simple Definition: Component Template = HTML + Angular Template Syntax

Component Template Flow

1
Component Class

Stores data and application logic.

→
2
Template

Uses HTML and Angular syntax.

→
3
Angular

Processes the template.

→
4
Browser

Displays the final UI.

External Template

An external template is stored in a separate HTML file and connected to the component using templateUrl.

student.component.ts
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    templateUrl: './student.component.html'
})
export class StudentComponent {

    studentName = 'Sam';

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

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

Inline Template

Instead of using a separate HTML file, a component can define its template directly using the template property.

student.component.ts
import { Component } from '@angular/core';

@Component({
    selector: 'app-student',
    template: `
        <h2>Student Details</h2>
        <p>Student Name: Sam</p>
    `
})
export class StudentComponent {
}
When to Use?

Inline templates can be useful for small components. Larger templates are generally easier to maintain in separate HTML files.

Interpolation in Templates

Interpolation is used to display component data inside HTML. It uses double curly braces.

student.component.ts
export class StudentComponent {

    studentName = 'Sam';

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

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

Student Name: Sam

Property Binding in Templates

Property binding connects a component property with a property of an HTML element.

Example
export class StudentComponent {

    imageUrl = 'assets/student.png';

}
HTML Template
<img [src]="imageUrl" alt="Student">

Event Binding in Templates

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

student.component.ts
export class StudentComponent {

    message = '';

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

}
student.component.html
<button (click)="showMessage()">
    Show Message
</button>

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

After clicking the button: Welcome Sam

Template Expressions

Angular templates can use expressions to display values calculated from component data.

Example
export class StudentComponent {

    marks = 85;

}
Template
<p>
    Marks: {{ marks }}
</p>

<p>
    Total: {{ marks + 15 }}
</p>
Expected Output

Marks: 85

Total: 100

Common Angular Template Features

{ }
Interpolation
{{ value }}

Displays component data.

[ ]
Property Binding
[property]

Binds values to element properties.

( )
Event Binding
(click)

Handles user events.

*
Template Features
@if / @for

Controls how template content is rendered.

Data Flow Between Component and Template

1
Component Class studentName = 'Sam'
→
2
Angular Template {{ studentName }}
→
3
Browser Student Name: Sam

Template Best Practices

✓

Keep templates simple and readable.

✓

Keep complex business logic inside the component or services instead of the template.

✓

Use meaningful property and method names.

✓

Reuse components where appropriate.

Summary

An Angular component template defines the user interface of a component.

Templates can use HTML together with Angular features such as interpolation, property binding and event binding.

Templates connect component data and logic with the user interface displayed in the browser.