Explain the difference between constructor and ngoninit in angular 6?



Explain the difference between constructor and ngoninit in angular 6?..

Answer / Meghna Singh

In Angular, the Constructor is a method that is called when an instance of a component or service is created. It is used to initialize properties and set up dependencies. The `ngOnInit` lifecycle hook, on the other hand, is called after the component's properties have been initialized and is used to perform any additional setup or initialization that requires data from services or other sources.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

What is a controller?

1 Answers  


What is a typescript decorator?

1 Answers  


What is fxflex in angular?

1 Answers  


Why is lazy evaluation good?

1 Answers  


What is ng command?

1 Answers  


What is the urlsegment interface in angular 7?

1 Answers  


What is angular json file?

1 Answers  


What is * ngfor?

1 Answers  


What's new in angular 8?

1 Answers  


Explain what are directives ? Mention some of the most commonly used directives in Angular.js application ?

1 Answers  


Who made redux?

1 Answers  


What do I have to do to trick the browser into doing what I want?

1 Answers  


Categories