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 Expressions

Angular Template Expressions are used to evaluate component data, perform simple calculations, access properties, and display dynamic values inside an Angular template.

What are Template Expressions?

A template expression is an expression written inside an Angular template that Angular evaluates and uses to display a value or provide a value for a binding.

Template expressions usually work with component properties, object properties, simple calculations, method calls, and conditional expressions.

Simple Definition

Angular Template Expressions allow the template to read and calculate values from the component and display them in the UI.

Template Expression Flow

Component Properties & Methods
→
Template Expression
→
Angular Evaluates Expression
→
Browser Displays Result

Common Template Expressions

Property

Displays a property from the component.

{{ studentName }}
Arithmetic

Performs simple calculations.

{{ marks + bonus }}
Method Call

Calls a component method.

{{ getStatus() }}
Conditional

Produces a value based on a condition.

marks >= 40 ? 'Pass' : 'Fail'

1. Property Expression

A property expression reads a value from the component class and displays it inside the Angular template.

Component
export class StudentComponent {

    studentName = 'Sam';

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

Student Name: Sam

2. Arithmetic Expressions

Angular template expressions can perform simple arithmetic calculations such as addition, subtraction, multiplication, and division.

Component
export class StudentComponent {

    marks = 80;
    bonus = 5;

}
Template
<p>
    Total Marks:
    {{ marks + bonus }}
</p>
Expected Output:

Total Marks: 85

3. Method Call Expression

A template expression can call a component method and display the value returned by that method.

Component
export class StudentComponent {

    studentName = 'Sam';

    getStudentLabel() {
        return 'Student: ' + this.studentName;
    }

}
Template
<p>
    {{ getStudentLabel() }}
</p>
Expected Output:

Student: Sam

4. Object Property Expression

Template expressions can access properties inside an object defined in the component.

Component
export class StudentComponent {

    student = {
        name: 'Sam',
        course: 'Angular',
        marks: 90
    };

}
Template
<p>
    Name: {{ student.name }}
</p>

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

<p>
    Marks: {{ student.marks }}
</p>
Expected Output:

Name: Sam

Course: Angular

Marks: 90

5. Conditional Expression

A conditional expression can be used to choose between two values depending on whether a condition is true or false.

Component
export class StudentComponent {

    marks = 85;

}
Template
<p>
    Result:
    {{ marks >= 40 ? 'Pass' : 'Fail' }}
</p>
Expected Output:

Result: Pass

6. Logical Expressions

Logical operators can be used inside simple template expressions when multiple conditions need to be evaluated.

Component
export class StudentComponent {

    marks = 85;
    attendance = 90;

}
Template
<p>
    Eligible:
    {{ marks >= 40 && attendance >= 75 ? 'Yes' : 'No' }}
</p>
Expected Output:

Eligible: Yes

7. Keeping Expressions Simple

Template expressions should be simple and focused on displaying or calculating values required by the user interface.

Good Example
<p>
    Total:
    {{ marks + bonus }}
</p>
Better Approach for Complex Logic
getStudentStatus() {
    // Complex logic
    return 'Pass';
}
Important

Avoid putting large business logic or complicated calculations directly inside the template. Keep complex logic inside the component or appropriate service.

Template Expression Examples

Expression Example Purpose
Property {{ studentName }} Display component data
Arithmetic {{ marks + bonus }} Calculate values
Object Property {{ student.name }} Access object data
Method Call {{ getStatus() }} Get calculated value
Conditional marks >= 40 ? 'Pass' : 'Fail' Display conditional value
Logical marks >= 40 && attendance >= 75 Evaluate multiple conditions

Complete Template Expression Example

student.component.ts
export class StudentComponent {

    studentName = 'Sam';

    marks = 85;

    bonus = 5;

    student = {
        course: 'Angular Full Stack',
        city: 'Pune'
    };

    getStatus() {
        return this.marks >= 40 ? 'Pass' : 'Fail';
    }

}
student.component.html
<div>

    <h2>
        Student Profile
    </h2>

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

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

    <p>
        City: {{ student.city }}
    </p>

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

    <p>
        Total Marks:
        {{ marks + bonus }}
    </p>

    <p>
        Result:
        {{ marks >= 40 ? 'Pass' : 'Fail' }}
    </p>

    <p>
        Status: {{ getStatus() }}
    </p>

</div>
Expected Output:

Student Profile

Name: Sam

Course: Angular Full Stack

City: Pune

Marks: 85

Total Marks: 90

Result: Pass

Status: Pass

Template Expression Best Practices

  • Keep template expressions simple and readable.
  • Use expressions mainly for UI-related values.
  • Use component properties to display dynamic data.
  • Move complex business logic into the component or service.
  • Avoid unnecessary calculations inside templates.
  • Use meaningful property and method names.

Summary

Angular Template Expressions allow templates to evaluate component data and display dynamic values in the user interface.

Common expressions include Property Expressions, Arithmetic Expressions, Object Property Expressions, Method Calls and Conditional Expressions.

Template expressions should remain simple, readable and focused on UI-related operations.