0

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?

Ignacio Peletier
  • 2,056
  • 11
  • 24
J M Smith
  • 25
  • 1
  • 11
  • May be xml-js works in the server side and not in the browser. You can check this answer for more info: https://stackoverflow.com/questions/45685100/xml-parser-that-works-for-both-browser-and-node-js – Krishna Mohan Sep 12 '19 at 10:09
  • ```onChanges``` will get called immediately data-bound properties if at least one has changed. It will not be activicate/called for all child components. – Dipak Telangre Sep 12 '19 at 10:26

1 Answers1

0

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.

kiranghule27
  • 439
  • 1
  • 7
  • 20