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

Two-Way Data Binding

Learn how Angular keeps component data and user input synchronized using two-way data binding.

What is Two-Way Data Binding?

Two-way data binding allows data to flow in both directions between the component and the template.

When the component value changes, the UI is updated. When the user changes the value in the UI, the component value is also updated.

Two-Way Data Binding Flow

1
Component

Component contains the application data.

↔
2
Binding

Angular creates a two-way connection.

↔
3
Template

Template displays and updates the value.

↔
4
User

User can change the value through the UI.

Main Two-Way Binding Concepts

M
ngModel

Commonly used for two-way binding with form controls.

I
Input

User input can update component data.

U
UI Update

Component changes are reflected in the UI.

S
Synchronization

Component and template values stay synchronized.

Two-Way Binding Syntax

Angular commonly uses the banana-in-a-box syntax [(ngModel)] for two-way binding.

Basic Syntax
<input [(ngModel)]="property">

The [(ngModel)] syntax combines property binding and event binding to create two-way data synchronization.

Basic Two-Way Binding Example

Component
export class StudentComponent {

    studentName = 'Sam';

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

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

Student: Sam

Updating Component Data from User Input

When the user changes the input value, Angular updates the corresponding component property.

Example
studentName = 'Sam';
Template
<input
    [(ngModel)]="studentName">

<p>
    Hello {{ studentName }}
</p>
Component
studentName
↔
ngModel
[(ngModel)]
↔
Input
User Value

Two-Way Binding with Multiple Controls

Multiple form controls can be connected to different component properties.

Component
studentName = 'Sam';
course = 'Angular Full Stack';
city = 'Pune';
Template
<input
    [(ngModel)]="studentName"
    placeholder="Student Name">

<input
    [(ngModel)]="course"
    placeholder="Course">

<input
    [(ngModel)]="city"
    placeholder="City">

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

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

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

Two-Way Binding with Checkbox

Two-way binding can also be used with checkbox controls.

Example
isActive = true;
Template
<input
    type="checkbox"
    [(ngModel)]="isActive">

<p>
    Active:
    {{ isActive }}
</p>
Example Output:

Active: true

Two-Way Binding with Select

A select control can also be synchronized with a component property.

Component
selectedCourse = 'Angular';
Template
<select [(ngModel)]="selectedCourse">

    <option value="Angular">
        Angular
    </option>

    <option value="Java">
        Java
    </option>

    <option value="DotNet">
        .NET
    </option>

</select>
Output:

Banana-in-a-Box Syntax

The syntax [(ngModel)] is commonly called "banana-in-a-box" because of the combination of square brackets and parentheses.

Syntax
[(ngModel)]="studentName"
Property Binding
[ngModel]
+
Event Binding
(ngModelChange)
=
Two-Way Binding
[(ngModel)]

One-Way vs Two-Way Data Binding

Feature One-Way Binding Two-Way Binding
Direction One direction Both directions
Common Syntax {{ value }} [(ngModel)]
User Input Does not automatically update property Updates component property
UI Update Component changes update UI Component and UI stay synchronized
Common Usage Displaying data Interactive form controls

Common Uses of Two-Way Binding

1
Form Inputs

Synchronize text input values with component properties.

2
Checkboxes

Keep checkbox state synchronized with component data.

3
Dropdowns

Synchronize selected values with component properties.

4
Interactive Forms

Keep user input and application data synchronized.

Complete Two-Way Binding Example

Student Component
export class StudentComponent {

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

}
Student Template
<h2>
    Student Registration
</h2>

<input
    [(ngModel)]="studentName"
    placeholder="Student Name">

<input
    [(ngModel)]="course"
    placeholder="Course">

<h4>
    Student:
    {{ studentName }}
</h4>

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

Student: Sam

Course: Angular Full Stack

Best Practices

1. Use two-way binding for synchronization

Use two-way binding when user input needs to update component data immediately.

2. Use it mainly with forms

Two-way binding is especially useful with interactive form controls.

3. Keep bindings simple

Avoid complex expressions inside two-way bindings.

4. Understand the data flow

Remember that two-way binding combines data display and user input updates.

5. Use one-way binding when synchronization is not required

Do not use two-way binding unnecessarily when the data only needs to move in one direction.

Summary

  • Two-way binding synchronizes component data and UI input.
  • [(ngModel)] is commonly used for two-way binding.
  • Changes in the component are reflected in the UI.
  • User input can update the component property.
  • Two-way binding is especially useful for forms.
  • It combines property binding and event-based updates.