This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
Component, Input, AfterViewInit, | |
ChangeDetectionStrategy, ChangeDetectorRef | |
} from '@angular/core'; | |
@Component({ | |
selector: 'app-instructor-list', | |
templateUrl: './instructor-list.component.html', | |
changeDetection: ChangeDetectionStrategy.OnPush | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<input type="text" [(ngMode)]="searchTerm"> | |
<button (click)="update()">Search</button> | |
<ul> | |
<li *ngFor="let instructor of instructors"> | |
{{ instructor }} | |
</li> | |
</ul> |