Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import {
Component, Input, AfterViewInit,
ChangeDetectionStrategy, ChangeDetectorRef
} from '@angular/core';
@Component({
selector: 'app-instructor-list',
templateUrl: './instructor-list.component.html',
changeDetection: ChangeDetectionStrategy.OnPush
})
export class InstructorListComponent implements AfterViewInit {
// Suppose this time the instructor list doesn't change after it arrives
@Input() instructors = [];
constructor(private cdr: ChangeDetectorRef) { }
// Wait until the view inits before disconnecting
ngAfterViewInit() {
// Since we know the list is not going to change
// let's request that this component not undergo change detection at all
this.crd.detach();
}
// Angular provides additional controls such as the following
// if the situation allows
// Request a single pass of change detection for the application
// this.cdr.markForCheck();
// Request a single pass of change detection for just this component
// this.cdr.detectChanges();
// Connect this component back to the change detection process
// this.cdr.reattach();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.