Home > OS >  Angular - Change Detection triggered when Strategy OnPush
Angular - Change Detection triggered when Strategy OnPush

Time:10-31

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.

CodePudding user response:

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

  • Related