Getting Started with Angular: Lesson 13 of 26

Handling Click Events

Up Next

Showing Active Users

Autoplaying in 7 seconds!

Cancel

To handle DOM events, we just need to wrap that event that we want to watch for with (). This is the event binding and we can watch for any events, even custom ones that we'll make ourselves in later lessons.

Table of Contents

    <div *ngIf="users">
        <ul class="list-group users-list">
        <li class="list-group-item"
            *ngFor="let user of users"
            (click)="selectUser(user)"
            [class.active]="user === activeUser">
                {{ user.name }} ({{ user.username }})
        </li>
        </ul>
    </div>

    Chris Sevilleja

    173 posts

    Founder of Scotch.io. Google Developer Expert in Web Technologies. Slapping the keyboard until something good happens.