How to use dependency injection (di) correctly in angular 2?



How to use dependency injection (di) correctly in angular 2?..

Answer / Amita Sharma

To use DI correctly in Angular 2, you need to create a service, mark it with @Injectable(), and then inject it into your components using the constructor. You should only inject services that are required by the component, and avoid creating new instances directly.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More AngularJS Interview Questions

What is service heroservice?

1 Answers  


What ide's are currently used for the development of angularjs?

1 Answers  


What is bazel and closure compiler in angular6?

1 Answers  


What is model in angular?

1 Answers  


What is the use of a double-click event in angularjs?

1 Answers  


What is afterviewinit?

1 Answers  


What is ng template in angular?

1 Answers  


What are the Pipes?

1 Answers  


How many modules can be used in a single html page?

1 Answers  


What would be a good use for ngzone service?

1 Answers  


What do you mean by module?

1 Answers  


What are static and public in angular?

1 Answers  


Categories