Reputation: 5316
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() { ...
My question is: Can we define module in multi place without global variable ?
Upvotes: 0
Views: 37
Reputation: 48972
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.
Upvotes: 3