所以我有点麻烦。我已经查看了从Injecting service 到 Directive的所有先前解决方案,但我真的不知道我做错了什么。我有一个如下所示的 authServices。
app.factory('authService', ['$http', function ($http) {
var authServiceFactory = {};
var _authentication = {
isAuth: false,
userName: ""
};
var _login = function (loginData) {
_authentication.isAuth = true;
_authentication.userName = loginData.userName;
}
appFactory.login = _login;
return appFactory;
}]);
我通过他们提出的方法注入它。
app.directive('headerNotification', ['authService', function (authService) {
return {
templateUrl: 'app/scripts/directives/header/header-notification/header-notification.html',
restrict: 'E',
replace: true,
link: function (scope) {
scope.authService = authService;
}
}
}]);
我的html是
<li data-ng-hide="authentication.isAuth">
我真的觉得我做错了。任何帮助将不胜感激。