ankush kumar
ankush kumar

Reputation: 3

Why does the Angular constructor run before ngOnChanges even though it's not a part of the lifecycle hooks?

I've noticed that in Angular, the constructor of a component runs before the ngOnChanges hook, despite the constructor not being considered a part of the lifecycle hooks. Could someone explain why this happens?

I've noticed that in Angular, the constructor of a component runs before the ngOnChanges hook, despite the constructor not being considered a part of the lifecycle hooks. Could someone explain why ?

Upvotes: -1

Views: 182

Answers (1)

Kiran
Kiran

Reputation: 350

If you think about it, you won't even have a component if you don't call a constructor function. Unless the functions are static, in any language, you need to construct the class's object before using any of it's function. That's why constructor will always be the first function to get called.

Upvotes: 0

Related Questions