lifecycle method onChange called before onInit and onCheck
See original GitHub issueI have attached onInit, onCheck, onChange, and onAllChangesDone lifecycle methods attached to a component(to reason about the sequence in which these methods get called). When the component is instantiated, its onChange method is called first, then onInit, onCheck and onAllChangesDone methods are called in sequence.
The docs says onChange
Notify a directive when any of its bindings have changed. This method is called right after the directive’s bindings have been checked, and before any of its children’s bindings have been checked. It is invoked only if at least one of the directive’s bindings has changed.
- Why
onChangeis called initially when the component is instantiating? - And whenever I change the value of a property on the component,
onChangeis fired first beforeonCheck. Is this intended behavior?
Here is a simple plunker for the above question -> http://plnkr.co/edit/sk6Xi7L6a7ob9xiRJaSJ?p=preview. View the console for the sequence.
Issue Analytics
- State:
- Created 8 years ago
- Comments:6 (3 by maintainers)

Top Related StackOverflow Question
+1 for
$onInitbeing called before$onChanges. I think that’s the way most people would expect it. I have many use cases for an init function which$onChangesdepends on already having been called. I don’t have a single use case for the other way around. There’s consternation in the AngularJS world about it too.This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.