auth is undefined - ui-router & Auth0

て烟熏妆下的殇ゞ 提交于 2019-12-25 04:12:39

问题


I'm using auth0 with ui-router. When the default route is loaded I can see the auth object is defined and contains methods. I get an undefined error when I try to access the value inside a controller. What's the best way of sharing this object with my controllers as as a reusable object?

!-- controller

module.controller('login', ['$scope', function($scope,auth) {

!---

}).run(function($rootScope, auth, store, jwtHelper, $state, $stateParams) {

    $rootScope.$on('$locationChangeStart', function() {
        if (!auth.isAuthenticated) {
            var token = store.get('token');
            if (token) {
                if (!jwtHelper.isTokenExpired(token)) {
                    auth.authenticate(store.get('profile'), token);
                } else {
                    $state.go('login');
                }
            }
        }

    });

});

回答1:


When you use explicit annotation (as you should), you need to explicitly define all the parameters. So, add 'auth' to that list:

module.controller('login', ['$scope', 'auth', function($scope, auth) {
..}]);


来源:https://stackoverflow.com/questions/27797009/auth-is-undefined-ui-router-auth0

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!