0

There are plenty of examples describing how DI operates at controller level in Angular.js but I am new to Angular and I am looking at the code of creating a new module and when I look at following code:

var app = angular.module("myApp", []); 

When it says that if this module is using other modules then we can specify them in in []. Is is also not a kind of Dependency injection?

So would it be correct statement to say that DI works at both Module and Controller level in Angular.JS?

1 Answer 1

2

Yes, DI works at both Module and Controller level.

But, the difference is

var app = angular.module("myApp", []); 

in the above line you inject modules that myApp module depends upon.

Whereas, at controller level, you inject services.

var app = angular.module("myApp", ['navigation']); 
app.controller("appController", function(navDataService){
});

So, when AngularJS bootstrap application, it look at module dependencies and load those modules and make the services available, so that, they can be injected into contoller.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.