init() vs OnInit in angular 1.5

84 views
Skip to first unread message

S kumar

unread,
Jul 10, 2016, 11:11:11 PM7/10/16
to AngularJS
We are migrating from angular 1.x to 1.5 and we do  have init() functions in all the controllers, as we have lifecycle hooks available in angular 1.5 , I just moved all the code from init() to
vm.$onInit() method. We usually put all the initialization stuff in init function before angular 1.5.   Is there difference between init() and $onInit() ? Am I doing anything wrong ?

Thanks in Advance

Sander Elias

unread,
Jul 11, 2016, 12:55:00 AM7/11/16
to AngularJS
Hi S,

There was no 'init' support in angular before $oninit. So the main difference is that angular calls the $onInit automatically when it needs it, and you needed to cal your init() functions yourself.

Regards
Sander

S kumar

unread,
Jul 12, 2016, 12:09:05 AM7/12/16
to AngularJS
Thank you
Reply all
Reply to author
Forward
0 new messages