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

2

1 Answer 1

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) {...}]);
Sign up to request clarification or add additional context in comments.

3 Comments

that may cause the problem. I did not add dependency at the beginning it was [] for angular .module.
why are you declaring your module twice and why can't you specify the dependency the first time?
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?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.