Skip to content

Improve documentation on https://angular.io/api/core/DoCheck#usage-notes #35596

@dyoo

Description

@dyoo

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.

Metadata

Metadata

Labels

featureLabel used to distinguish feature request from other issuesfreq1: low

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions