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

DOM Events in Angular

Learn how Angular works with browser DOM events such as click, input, change, keyboard and mouse events.

CIIT Training Institute

DOM events allow Angular applications to respond to actions performed by users on HTML elements.

What are DOM Events?

DOM events are actions or occurrences that happen on HTML elements because of user interaction or browser activity.

For example, when Sam clicks a button, Pradnya types in an input box, or Samiksha presses a keyboard key, the browser generates an event.

👤 User Action Student interacts
→
🌐 DOM Event Browser generates event
→
⚡ Angular Event binding detects it
→
🔧 Method Component logic runs

Common DOM Event Categories

🖱️
Mouse Events

Events generated through mouse interactions.

click, dblclick, mouseenter
⌨️
Keyboard Events

Events generated when keyboard keys are pressed or released.

keydown, keyup
📝
Input Events

Events generated when values inside input controls change.

input, change
📋
Form Events

Events generated while interacting with forms.

submit, reset

1. Click Event

The click event occurs when the user clicks an HTML element such as a button.

HTML
<button (click)="showMessage()">
    Click Me
</button>
TypeScript
showMessage() {

    console.log(
        'Welcome to CIIT Training Institute'
    );

}
Output:

CIIT Training Institute

Clicking the button executes the showMessage() method.

2. Double Click Event

The dblclick event occurs when an element is double-clicked.

Example
<button (dblclick)="showDetails()">
    Double Click
</button>
TypeScript
showDetails() {

    console.log(
        'Student details opened'
    );

}

3. Input Event

The input event occurs whenever the value of an input element changes while the user is typing.

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

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

    console.log(value);

}
Live Example:

Angular can capture every input event.

4. Change Event

The change event occurs when the value of a form control changes.

HTML
<select (change)="selectCourse($event)">

    <option>Angular Full Stack</option>
    <option>.NET Full Stack</option>
    <option>Java Full Stack</option>

</select>
TypeScript
selectCourse(event: Event) {

    const course =
        (event.target as HTMLSelectElement).value;

    console.log(course);

}

5. Keyboard Events

Angular can handle keyboard events using keydown and keyup.

⬇️
Key Down

Occurs when a keyboard key is pressed.

(keydown)
⬆️
Key Up

Occurs when a pressed keyboard key is released.

(keyup)
Example
<input
    (keydown)="keyPressed($event)"
    placeholder="Press a key">
TypeScript
keyPressed(event: KeyboardEvent) {

    console.log(
        'Key:',
        event.key
    );

}

6. Mouse Events

Angular can respond to different mouse interactions.

Event Syntax Description
Click (click) User clicks an element
Double Click (dblclick) User double-clicks an element
Mouse Enter (mouseenter) Mouse enters an element
Mouse Leave (mouseleave) Mouse leaves an element
Mouse Down (mousedown) Mouse button is pressed
Mouse Up (mouseup) Mouse button is released

7. Form Events

Angular can handle form-related events such as submit.

HTML
<form (submit)="submitForm()">

    <input
        type="text"
        placeholder="Student Name">

    <button type="submit">
        Submit
    </button>

</form>
TypeScript
submitForm() {

    console.log(
        'Student form submitted'
    );

}

Working with the Event Object

Angular provides the $event object when the event details are required.

User Action Types a value
→
$event Event information
→
TypeScript Reads event data
→
UI / Logic Application responds

Complete Example – CIIT Student Events

student.component.ts
selectedStudent = '';

selectStudent(name: string) {

    this.selectedStudent = name;

}

showWelcome() {

    console.log(
        'Welcome to CIIT Training Institute'
    );

}
student.component.html
<h2>
    CIIT Training Institute
</h2>

<p>
    Select a student:
</p>

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

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

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

<p>
    Selected:
    {{ selectedStudent }}
</p>
Expected Output:

CIIT Training Institute

Select a student:

Selected: Sam

DOM Event Handling Best Practices

  • Use the correct DOM event for the required user interaction.
  • Keep event handler methods simple and readable.
  • Use $event only when event information is required.
  • Use meaningful method names such as selectStudent().
  • Avoid putting complex business logic directly inside templates.
  • Keep reusable application logic inside appropriate services.
  • Test mouse, keyboard, input and form events properly.

Summary

DOM events allow Angular applications to respond to user interactions with HTML elements.

Important DOM events include click, dblclick, input, change, keydown, keyup, mouseenter, mouseleave and submit.

Angular event binding connects these browser events with component methods and application logic.