-3

Can we not perform all the same operations it does in the constructor?

Mike Feltman
  • 5,160
  • 1
  • 17
  • 38
  • 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
  • 2
    Possible 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 Answers1

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

Community
  • 1
  • 1
sheplu
  • 2,937
  • 3
  • 24
  • 21