0

I have problem when define angularjs module in multi place

angular.module('ty', [])
.directive('v1', function() {
      return{
        restrict: "E",      
        template: '<div>1</div>'
      };
});

angular.module('ty', [])
.directive('v2', function() {
      return{
        restrict: "E",      
        template: '<div>2</div>'
      };
})

This problem can solve by define a variable like this

var a = angular.module('ty', []);
a.directive('v1', function() { ...
a.directive('v2', function() { ...

http://jsfiddle.net/66Je2/1/

My question is: Can we define module in multi place without global variable ?

1
  • 1
    See if this helps -- "Using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module." -- docs.angularjs.org/guide/module Commented Feb 16, 2014 at 9:35

1 Answer 1

3

Quoted from the docs:

Beware that using angular.module('myModule', []) will create the module myModule and overwrite any existing module named myModule. Use angular.module('myModule') to retrieve an existing module.

In your case, your are re-creating your module again and removing the previous one.

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.