I have come across below example in Angular 2 documentation
@Component({
selector: \'cmp\',
changeDetection: ChangeDetectionStrategy.OnPush,
template: `Num
Using ChangeDetectionStrategy.OnPush
tells Angular not to perform change detection on your component (i.e. updating its view) unless one or more of the component's inputs has changed (these inputs should be immutable objects).
For any events that come from within the component itself and require the view to be updated, you have to explicitly tell the change detector to look for changes in that component on its next change detection run.
In this snippet, ref
is a reference to the change detector. Calling ref.markForCheck()
tells the change detector that something has happened that will change the view (i.e. numberOfTicks
has been incremented) and it needs to recompute it.