Video Course

Getting Started with Angular v2+: 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.

<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

162 posts

Co-founder of Scotch.io. Slapping the keyboard until something good happens.