The Anubhav portal was launched in March 2015 at the behest of the Hon'ble Prime Minister for retiring government officials to leave a record of their experiences while in Govt service .
We use cookies to ensure you have the best browsing experience on our website. By using our site, you
acknowledge that you have read and understood our
Cookie Policy &
Privacy Policy.
What exactly is
OnInit?OnInitis an interface provided by Angular.ngOnInit()ngOnInit()after the component’s constructor runs and after all@Input()values are set.Why do we use
OnInit?You use
OnInitwhen you want to:@Input()valuesBasic example
Execution order
ngOnInit()Constructor vs
ngOnInit()ngOnInit()Best practice:
ngOnInit()for initialization logicExample with
@Input()When NOT to use
OnInitngOnChangesngOnDestroyngAfterViewInitSummary
OnInitis an Angular lifecycle hookngOnInit()