Description
The "Usage notes" documentation on DoCheck has no useful content in it other than that DoCheck is an interface with an ngDoCheck() method. It can be greatly improved with a better example.
Something like the following:
@Component({
selector: 'my-person-display',
template: `This is {{person.name}}.`,
changeDetection: ChangeDetectionStrategy.OnPush,
})
class MyComponent implements DoCheck, OnChanges {
@Input() person = {name: 'Anemone'};
constructor(private readonly cdr: ChangeDetectorRef) {}
ngOnChanges() {
this.oldPersonName = this.person.name;
}
ngDoCheck() {
// Implement a custom change-detector to find if this.person is mutated.
if (this.oldPersonName !== this.person.name) {
this.oldPersonName = this.person.name;
this.cdr.markForCheck();
}
}
}
would help in motivating why this hook exists.
Description
The "Usage notes" documentation on DoCheck has no useful content in it other than that DoCheck is an interface with an ngDoCheck() method. It can be greatly improved with a better example.
Something like the following:
would help in motivating why this hook exists.