javascript - Calling Services in a custom directive -


i have custom directive working fine, untill added services it, giving me "error: ng:areq bad argument" cant figure out why.

my directive:

angular.module('myapp')     .directive('modalcontent',[         '$uibmodal',         'userservice'],         function($uibmodal, userservice){         return {             restrict: 'a',             priority: 100,             link: function($scope, element, attrs) {                 element.on( 'click', function( evt ){                      console.log("click , stop");                      evt.preventdefault()                     evt.stopimmediatepropagation();                      $scope.$apply(function(){                         console.log("call modal");                     });                  });             }         };     }); 

try initializing angular module before creating directive:

angular.module('myapp',[]); 

after that, can use code.


edit:

the error due syntax error, have ] after 'userservice' correct definition of directive is:

angular.module('myapp')     .directive('modalcontent',[         '$uibmodal',         'userservice',         function($uibmodal, userservice){         return {             restrict: 'a',             priority: 100,             link: function($scope, element, attrs) {                 element.on( 'click', function( evt ){                      console.log("click , stop");                      evt.preventdefault()                     evt.stopimmediatepropagation();                      $scope.$apply(function(){                         console.log("call modal");                     });                  });             }         };     }]); 

also notice change in end: }]); instead of });


Comments