Can we not perform all the same operations it does in the constructor?
Asked
Active
Viewed 60 times
-3
-
There is an answer on this page: https://stackoverflow.com/questions/35763730/difference-between-constructor-and-ngoninit – David Aug 07 '17 at 19:30
-
The differences between `ngOnInit()` and constructors notwithstanding, executing complex logic in a constructor is definitely an antipattern – Kai Aug 07 '17 at 19:30
-
2Possible duplicate of [Difference between Constructor and ngOnInit](https://stackoverflow.com/questions/35763730/difference-between-constructor-and-ngoninit) – Igor Aug 07 '17 at 19:30
1 Answers
1
ngOnInit
is a life cycle hook called by Angular to indicate that Angular is done creating the component.The Constructor is a default method of the class that is executed when the class is instantiated and ensures proper initialization of fields in the class and its subclasses.
Someone give a really good explanation here Difference between Constructor and ngOnInit