Explain the need for DI in AngularJs?

devquora
devquora

Posted On: Feb 22, 2018

 

Dependency Injection or DI, is a design pattern of injecting objects into the angular components instead of angular components creating for themselves. The advantage of this is, we can separate our web application in multiple logical units, we can reuse these multiple logical units anywhere in our application. In angular dependency injection is the main concept without which angular does not work. For example, In order to use services(built-in or custom or both) we have to inject these services in our controller as shown below.


angular.controller('myCntrl',function($scope,$http)
{
 //Use your $http service here 

});

    Related Questions

    Please Login or Register to leave a response.

    Related Questions

    AngularJS Basic Interview Questions

    What is AngularJS?

    AngularJS is a javascript framework which helps in developing web applications in MVC architectural pattern & SPA or..

    AngularJS Basic Interview Questions

    What are angular directives?

    Angular directives are the attributes which are decorated on the html tags or elements of an html page. Directives have ..

    AngularJS Basic Interview Questions

    What are custom directives?

    Angular provides the ability to create our own directives to implement our own custom templates or logic in our web appl..