Reputation: 21
According to Angular.io Angular Documentation on Life cycle hooks The purpose of OnInit : Initialize the directive/component after Angular first displays the data-bound properties and sets the directive/component's input properties.
So what exactly happens when it is said component has initialized. Does it mean all the variables are initialized or the component's template is displayed or both?
Upvotes: 1
Views: 3059
Reputation: 32535
So what exactly happens when it is said component has initialized. Does it mean all the variables are initialized or the component's template is displayed or both?
Markup is rendered, bindings are bound, NO child view/components are injected. In other words, you can start initializing your component in context of its inputs. You can threat it as "Angular Construction" method and do all component initialization stuff there. It is very similar to @PostConstruct
concept from EJB.
Upvotes: 1
Reputation: 1751
ngOnInit
is useful after angular is done with creation of the component. So, when constructor finishes its work, the component is said to be initialized and it has specified properties which you can initialize in ngOnInit
now.
I hope this helps!
Upvotes: 0