0

I am trying to dependency inject a module into another—the former is simply an empty module.

angular.module('module1', []);
angular.module('module2', [])
.controller('Module2Ctrl', ['module1', '$scope', function (module1, $scope) {
  $scope.expression = 'hello!';
}]);

HTML:

<html ng-app="module2">
  <body ng-controller="Module2Ctrl">
    <h1>{{expression}}</h1>
  </body>

</html>

I'm getting the dreaded Unknown provider: module1Provider <- module1 <- Module2Ctrl message.

What's going on? I believe everything is defined as it should be—though module1 has no definitions, I can't find information anywhere on what would stop this from working.

Plnkr: http://plnkr.co/edit/goMVFRNuPgG6iIpGYI1Y?p=preview

Thanks :-)

2 Answers 2

1

You inject providers (such as factories, services, ...), not modules. Remove the module1 injection and it will work. What you're thinking of doing is probably declaring module2 as a module dependency of module1:

angular.module('module1', ['module2']);

and then ng-app="module".

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

Comments

1

angular.module can not injected inside a controller,Only one angular.module can be injected inside another module.

angular.module('module2', ['module1'])

You should never do that angular. Only angular components are inject-able like service,controller, factory, filter, provider,etc.

For initializing angular on page you could do angular.bootstrap

angular.bootstrap(document,["module2"])

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.