0

I am studying about AngularJS. What is difference between $onInit = () => {} and ngOnInit() { }?

Jin Huh
  • 49
  • 5
  • 1
    One is for [AngularJS](https://angularjs.org/), an obsolete web framework, which will soon be abandoned. The other is for [Angular](https://angular.io/), another, different web framework, which is alive and well. – JB Nizet Nov 25 '19 at 16:49
  • You mean ngOninit() will soon be abandoned soon, right? – Jin Huh Nov 25 '19 at 18:37
  • No. AngularJS will. ngOnInit is one of the hooks of Angular components. – JB Nizet Nov 25 '19 at 19:15

2 Answers2

2

The first one is used in angularjs, the first version of this framework made in javascript, ngOnInit() is used in Angular2+, this is another framework wrote in Typescript. I recommend you to study Angular2+, because Angularjs is deprecated, and On July 1, 2018 AngularJS entered a 3 year Long Term Support period. The last stable version of Angular is 8 at this moment

2

ngOnInit() - This is part of digest cycle of Angular $onInit - This is not a part of digest cycle. Called on each controller after all the controllers on an element have been constructed and had their bindings initialized (and before the pre & post linking functions for the directives on this element). refer: Why to use $onInit in AngularJS?