Angular - Change Detection triggered when Strategy OnPush

293 Views Asked by At

I'm triggering tick() and detectChanges() in the root component. In root component I have one child with onPush strategy, which logically means it shouldn't triger that child component if data has not changed.

Really small example about this issue: https://github.com/michalgrzegorczyk-dev/change-detection

Why ChildWrapperComponent runs ngDoCheck() in this case? It's OnPush! Why?

NgZone is disabled. The reset of the components works as expected, only root components are triggerend even it's OnPush.

1

There are 1 best solutions below

0
StPaulis On BEST ANSWER

When you run detectChanges() manually, the component itself and all the children will be checked for changes.

Docs: detectChanges()

Checks this view and its children. Use in combination with detach to implement local change detection checks.

Angular|Detect Changes