I am trying to add a few custom angular directives to be called on several views. that said, below is how I have the code setup
app.js
angular
.module('app', [
'app.routes',
'app.config',
'app.users',
'app.plans'
]);
usersCtrl.js
angular
.module('app.users.controllers')
.controller('usersCtrl', usersCtrl)
usersCtrl.$inject = ['$scope', '$http', '$window'];
function usersCtrl($scope, $http, $window) {
/*controller code here*/
}
plansCtrl.js
angular
.module('app.plans.controllers')
.controller('plansCtrl', plansCtrl)
plansCtrl.$inject = ['$scope', '$http', '$window'];
function plansCtrl($scope, $http, $window) {
/*controller code here*/
}
now if I add directive to say users like below
usersCtrl.js with a directive attached
angular
.module('app.users.controllers')
.controller('usersCtrl', usersCtrl)
.directive('myFirstDirective', ['$window', function($window) {
return {
restrict: 'A',
link: function (scope, element, attrs)
{
alert('my first directive')
}
};
}]);
usersCtrl.$inject = ['$scope', '$http', '$window'];
function usersCtrl($scope, $http, $window) {
/*controller code here*/
}
with the above setting if I call directive on users view it works as it should but then if I call it within plan view it also works. that being said, what's the best way to structure directives), where to place custom directive and access those where needed.