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

Event Handling Introduction

Learn how Angular handles user interactions such as clicks, keyboard actions, input changes, mouse events and form submissions.

CIIT Training Institute: Event handling helps you build interactive Angular applications by responding to actions performed by users.

What is Event Handling?

Event handling in Angular is the process of responding to actions performed by the user on a web page.

For example, when Sam clicks a button, Angular can execute a component method. Similarly, when Pradnya types inside an input box, Angular can capture the entered value.

1 User Action Click / Input / Key
→
2 DOM Event Browser detects event
→
3 Angular Binding (click), (input)
→
4 Component Method Business logic
→
5 UI Update Updated screen

Common Angular Events

🖱️
Click Events

Execute an action when the user clicks a button or element.

⌨️
Input Events

Capture values while the user types inside an input field.

🔤
Keyboard Events

Handle keyboard actions such as keyup and keydown.

📝
Form Events

Handle form submission and changes in form controls.

Angular Event Binding Syntax

Angular uses parentheses () to bind DOM events.

HTML Template
<button (click)="showMessage()">
    Click Me
</button>
Explanation:

(click) → Angular event binding

showMessage() → Component method

Handling Event in Component

The event can call a method defined inside the Angular component class.

student.component.ts
showMessage() {
    console.log('Welcome to CIIT Training Institute');
}
When the button is clicked, Angular calls the showMessage() method.

Using the Event Object

Angular provides the $event object when we need information about the event that occurred.

HTML
<input
    type="text"
    (input)="onInput($event)"
    placeholder="Enter your name">
TypeScript
onInput(event: Event) {

    const value =
        (event.target as HTMLInputElement).value;

    console.log(value);
}
Example:

Angular can capture the value entered by the user.

Common DOM Events

Event Syntax When It Occurs
Click (click) When an element is clicked
Double Click (dblclick) When an element is double-clicked
Input (input) When input value changes while typing
Change (change) When an input value changes
Key Up (keyup) When a keyboard key is released
Key Down (keydown) When a keyboard key is pressed
Mouse Enter (mouseenter) When mouse enters an element
Mouse Leave (mouseleave) When mouse leaves an element
Submit (submit) When a form is submitted

Complete Example – CIIT Student Selection

Let's create a simple example where CIIT students can be selected using buttons.

student.component.html
<h3>CIIT Training Institute</h3>

<button
    (click)="selectStudent('Sam')"
    class="btn btn-primary me-2">
    Sam
</button>

<button
    (click)="selectStudent('Pradnya')"
    class="btn btn-primary me-2">
    Pradnya
</button>

<button
    (click)="selectStudent('Samiksha')"
    class="btn btn-primary">
    Samiksha
</button>

<p>
    Selected Student: {{ selectedStudent }}
</p>
student.component.ts
selectedStudent = '';

selectStudent(name: string) {
    this.selectedStudent = name;
}

CIIT Training Institute

Select a student:

Selected Student: Sam

Event Handling Flow

1. User Clicks button
→
2. Event click event occurs
→
3. Angular (click) detects event
→
4. Method selectStudent()
→
5. UI Student name updates

Event Handling Best Practices

  • Keep event handler methods small and readable.
  • Use meaningful method names such as selectStudent().
  • Use $event when event information is required.
  • Avoid putting complex business logic directly inside templates.
  • Use appropriate DOM events for the required interaction.
  • Keep reusable logic inside services when required.
  • Follow consistent naming conventions in Angular components.

Summary

Angular event handling allows applications to respond to user actions.

  • Events make Angular applications interactive.
  • Parentheses () are used for event binding.
  • Methods can be called when events occur.
  • $event provides event information.
  • Angular supports click, input, keyboard, mouse and form events.
  • CIIT Training Institute examples help students understand real-world event handling.