DEV Community

Len Vaz 💙
Len Vaz 💙

Posted on

Why does angular run change detection Checks after a component is detached from the view?

A simple component using OnPush change detection. Detached the component in ngOnInit after the first cycle. Even after doing so, the life cycle hooks used here are being called when a button click from a different component triggers the change.

Would love to have any help understanding this!

Component Template

Component Class

The logs fired from the hooks can be seen below:

Console Logs for life cycle hooks

Top comments (1)

Collapse
 
gaurangdhorda profile image
GaurangDhorda

Thats because setTimeout internally called ngZone and detect changes for components. Same things are applied for async pipe too!