javascript - TypeError: authService.isAuthenticated is not a function -
i'm trying call isauthenticated method in controller, telling me not function. below snippet of code.
the 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; }); } }})();
and in app.js (the main module) includes dependencies
angular .module('app', ['admin','app.router','app.auth','app.constants','user'])
authservice resides in app.auth.js
(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; }); } }})();
does know did wrong here? need helps
it looks your'e injecting multiple things , declaring one. should like:
navcontroller.$inject = ['user_roles','auth_events','authservice','$http']; /* @nginject */ function navcontroller(user_roles,auth_events,authservice,$http) {
Comments
Post a Comment