1
var myTestApp=angular.module('myApp',[]);
myTestApp
  .controller('MyController',
    ['$scope', 'EmailParser',
      function($scope, EmailParser) {
    ...}]);

angular.module('myApp', ['emailParser'])
  .controller('MyController',
    ['$scope', 'EmailParser',
      function($scope, EmailParser) {...}]);

I will encounter error when I use above method to add the dependency of emailParser into an agular module. What is the right way to do it? NOTE: emailParser is declared in the actual code

Update

I don't want certain controller have access to email Parser module. I am not sure if this kind of thinking is right. What is the best practice for adding dependency after the declaration of module at the beginning? Am I going the right way to do it?

The error I received was

Error: [ng:areq] Argument 'MyController' is not a function, got undefined

I am sure if my way of thinking how it work is right. Is that I want add emailParser into the module not a good idea, or not a good practice?

Thank You

ey dee ey em
  • 7,991
  • 14
  • 65
  • 121
  • [Don't confound module declaration and module utilisation](http://stackoverflow.com/questions/23982763/angular-module-order-of-loading/23983080#23983080). That's said, what's your error? – Blackhole Jun 03 '14 at 19:26
  • @Blackhole I realize it did not fix the issue, so I updated the question just now. Thanks! – ey dee ey em Jun 03 '14 at 19:38

1 Answers1

0

You must add dependencies when you first declare your module. Any reason just this isn't working:

angular.module('myApp', ['emailParser'])
  .controller('MyController',
    ['$scope', 'EmailParser',
      function($scope, EmailParser) {...}]);
rob
  • 17,995
  • 12
  • 69
  • 94
  • that may cause the problem. I did not add dependency at the beginning it was [] for angular .module. – ey dee ey em Jun 03 '14 at 20:16
  • why are you declaring your module twice and why can't you specify the dependency the first time? – rob Jun 03 '14 at 20:17
  • so I assume then that in a single ng-app, angular.module dependency can not be..inserted after the declaration of the angular.module itself? – ey dee ey em Jun 03 '14 at 20:48