markChildForCheck abstract method

void markChildForCheck(
  1. Object child
)

Invokes markForCheck on child's associated ChangeDetectorRef.

This only works if child is a component instance obtained from any of the following annotations:

  • @ContentChild()
  • @ContentChildren()
  • @ViewChild()
  • @ViewChildren()

Note that the static type of child need not be a component so long as the underlying implementation is.

On any other argument, this method is still safe to call, but has no effect. This allows the caller to use this method without explicit knowledge of whether or not child is backed by a component using ChangeDetectionStrategy.onPush.

@Component(
  selector: 'example',
  template: '<ng-content></ng-content>',
  changeDetection: ChangeDetectionStrategy.onPush,
)
class ExampleComponent {
  ExampleComponent(this._changeDetectorRef);

  final ChangeDetectorRef _changeDetectorRef;

  @ContentChildren(Child)
  List<Child> children;

  void updateChildren(Model model) {
    for (final child in children) {
      // If child is implemented by an OnPush component, imperatively
      // mutating a property like this won't be observed without marking
      // the child to be checked.
      child.model = model;
      _changeDetectorRef.markChildForCheck(child);
    }
  }
}

Prefer propagating updates to children through the template over this method when possible. This method is intended as a last resort to facilitate migrating components to use ChangeDetectionStrategy.onPush.

Implementation

void markChildForCheck(Object child);