top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

What is dependency injection and how does it work in AngularJs?

+1 vote
394 views
What is dependency injection and how does it work in AngularJs?
posted Jan 10, 2017 by Ramya

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes

Dependency injection is a process where we inject the dependent objects rather than consumer creating the objects. DI is everywhere in Angular or we can go one step ahead and say Angular cannot work without DI.

For example in the below code “$scope” and “$http” objects are created and injected by the angular framework. The consumer i.e. “CustomerController” does not create these objects himself rather Angular injects these objects.

function CustomerController($scope,$http)
{
// your consumer would be using the scope and http objects
}
answer Jan 11, 2017 by Manikandan J
...