Ich versuche, isAuthenticated-Methode in meinem Controller aufzurufen, aber es sagt mir, ist keine Funktion. Unten ein Ausschnitt meines Codes.TypeError: authService.isAuthenticated ist keine Funktion
der Controller
(function() {
'use strict';
angular
.module('app')
.controller('NavController', NavController);
NavController.$inject = ['USER_ROLES','AUTH_EVENTS','authService','$http'];
/* @ngInject */
function NavController(authService) {
var vm = this;
vm.name = '';
activate();
////////////////
function activate() {
authService.isAuthenticated().then(function(response){
vm.isLoggedin=response;
});
}
}})();
und in app.js (das Hauptmodul) es umfasst alle Abhängigkeiten
angular
.module('app', ['admin','app.router','app.auth','app.constants','user'])
authService in app.auth.js residiert
(function() {
'use strict';
angular
.module('app.auth',['LocalStorageModule','app.constants'])
.factory('authService', authService);
authService.$inject = ['$http','localStorageService','USER_ROLES'];
/* @ngInject */
function authService($http,localStorageService,USER_ROLES) {
var service = {
isAuthenticated: isAuthenticated
};
return service;
////////////////
function isAuthenticated(){
return $http({
method: 'GET',
url: '/api/v1/isAuthenticated',
headers: {
'Authorization': 'Bearer '+localStorageService.get('token')
}
}).then(function successCallback(response) {
return true;
}, function errorCallback(response) {
return false;
});
}
}})();
Weiß jemand, was ich hier falsch gemacht habe? Notwendigkeit hilft
Beachten Sie, dass die Reihenfolge wichtig ist. [Property Annotation] (https://docs.angularjs.org/guide/di#-inject-property-annotation) –
cool, dass mein Problem löst. Vielen Dank! –