I'm having a problem when trying to inject myFactory into myDirective. I need myfactory.myMethod to get a dynamic templateUrl based on a certain event.
That's what I'm trying right now:
(function () {
'use strict';
angular
.module('myApp')
.directive('myDirective', ['myFactory', function (myFactory) {
var directive = {
restrict: 'E',
templateUrl : function(myFactory){
if(myFactory.myMethod()){
return '/app/hello.html'
}
return '/app/world.html'
},
controller : 'MyController',
controllerAs : 'myCtrl',
bindToController : true
};
return directive;
}]);
})();
I get the following error
myFactory.myMethod is not a function
I tried looking at various solutions also on SO but I wasn't able to find the proper one.
myFactory is a simple Factory
(function () {
'use strict';
angular
.module('myApp')
.service('myFactory', function () {
function myMethod() {
. . .
}
//Or
var myMethod = function(){
. . .
}
return {
myMethod: myMethod
}
});
})();
How can I fix this?
Thanks in advance.
myFactory.var myMethod = function(){ .... } ;Gulp. My App module definition looks like(function(){ 'use strict'; angular.module('myApp', [modules . . .]); })();