Skip to content

Instantly share code, notes, and snippets.

View dpsthree's full-sized avatar

Paul Spears dpsthree

View GitHub Profile
@dpsthree
dpsthree / instructor-list.component.html
Created September 21, 2017 03:37
Example of trackBy
<!--
As the references change ngFor will continuously regenerate the DOM
However, the presence of trackBy provides ngFor some help.
It modifies the behavior so that it compares new data to old based on
the return value of the supplied trackBy method.
This allows Angular to reduce the amount of DOM update needed
-->
<ul>
<li *ngFor="let instructor of instructorList: trackBy: trackByName" >
<span>Instructor Name {{ instructor.name }}</span>
import {
Component, Input, AfterViewInit,
ChangeDetectionStrategy, ChangeDetectorRef
} from '@angular/core';
@Component({
selector: 'app-instructor-list',
templateUrl: './instructor-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
@dpsthree
dpsthree / instructor-list.component.html
Created September 21, 2017 03:15
Simplest OnPush Example
<!--
Since all bound values arrive as inputs
this component is suitable for use with OnPush
-->
<ul>
<li *ngFor="let instructor of instructors">
{{ instructor }}
</li>
</ul>
@dpsthree
dpsthree / app.component.html
Created September 21, 2017 03:02
Filtering a list in response to a click event
<input type="text" [(ngMode)]="searchTerm">
<button (click)="update()">Search</button>
<ul>
<li *ngFor="let instructor of instructors">
{{ instructor }}
</li>
</ul>