Search code examples
angulartypescriptangular-componentsangular-lifecycle-hooks

Are Angular lifecycle hooks called on every component of a nested component structure?


This is just a conceptual question. I am trying to learn more about how Angular lifecycle hooks work.

My question is, if I have a nested component structure like below:

<parent-component>
    <first-child>
        <first-grandchild>
        </first-grandchild>
    </first-child>
    <second-child>
    </second-child>
</parent-component>

If eg the onChanges lifecycle hook is activated for one component, will it be activated for all child/sibling components?

If the answer to that is no, is there a non-hacky way to implement something to replicate that behaviour, or is it not supported?


Solution

  • Change detection flows from parent to child components. As for ngOnChanges lifecycle, it is called when a bounded property of a component(decorated with @Input() decorator) changes in the parent component.

    This article explains it quite well.