I thought I was pretty clear on how Angular Change detection works after this discussion: Why is change detection not happening here when [value] changed?
But take a
That's by design.
If you have component with OnPush
change detection then its detectChangesInternal
function won't be triggered unless one of four things happens:
@Inputs
changes~2.4.x
~4.x.x
Note: @Input
s should be presented in template. See issue https://github.com/angular/angular/issues/20611 and comment
Caveats: There is some difference here between 2.x.x and 4
Angular ChangeDetectionStrategy.OnPush with child component emitting an event
~2.4.x
~4.x.x
ChangeDetectorRef.markForCheck()
)ChangeDetectorRef.markForCheck()
internallyprivate _updateLatestValue(async: any, value: Object): void {
if (async === this._obj) {
this._latestValue = value;
this._ref.markForCheck();
}
}
https://github.com/angular/angular/blob/2.4.8/modules/%40angular/common/src/pipes/async_pipe.ts#L137
In other words if you set OnPush
for component then after the first checking component's status will be changed from CheckOnce
to Checked
and after that it's waiting as long as we do not change status. It will happen in one of three things above.
See also:
There are also good explanations of how angular2 change detection work:
Here is Live Example(Thanks to Paskal) that explains onPush
change detection. (Comp16
looks like your component. You can click at this box).