Below are the directives index:
'use strict';
import SignupService from './core/services/signup.service';
import FooterDirective from './components/footer/footer.directive';
import MenuDirective from './components/menu/menu.directive';
export default angular.module('index.components', [])
.directive('footer', FooterDirective)
.directive('menu', [MenuDirective, function(SignupService) {}]);
and the directive code:
import tmpl from './menu.tpl.html';
class Menu {
constructor($scope) {
this.scope = $scope;
this.restrict = 'AC';
this.transclude = true;
this.replace = true;
this.templateUrl = tmpl;
this.scope = {
ngSrc: "@",
};
}
link(scope, elem, attrs) {
console.log(scope.SignupService);
scope.logoutCall = () => {
this.SignupService.logoutSubmit();
}
}
}
function factory() {
"ngInject";
return new Menu(...arguments);
}
export default factory;
I am trying to access the Signup Service
from the Menu directive, but encountering an error -
Incorrect injection token! Expected service name as string, got function factory()
. What is the best practice for injecting a service into a directive? Thank you.