Last active
February 17, 2020 15:41
-
-
Save dpsthree/ad8f387c763858c69054026f13924e04 to your computer and use it in GitHub Desktop.
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 | |
}) | |
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.cdr.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(); | |
} |
Fixed, thanks!
Welcome :)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this.crd.detach();
should bethis.cdr.detach();
;)