ng-token-auth错误 - 阻止应用加载

时间:2017-06-13 23:57:43

标签: ruby-on-rails angularjs

我有一个AngularJs + Ruby on Rails应用程序,我正在尝试集成ng-token-auth,但是当我的应用加载时,我收到以下警告和错误,阻止了应用实际加载:

jQuery.Deferred exception: Cannot read property 'validateOnPageLoad' of 
undefined TypeError: Cannot read property 'validateOnPageLoad' of 
undefined
-
TypeError: Cannot read property 'proxyIf' of undefined
    at Object.apiUrl (ng-token-auth.self-50017ec….js?body=1:689)
    at ng-token-auth.self-50017ec….js?body=1:789
    at Object.invoke (angular.self-5592af5….js?body=1:4626)
    at request (ng-token-auth.self-50017ec….js?body=1:786)
    at processQueue (angular.self-5592af5….js?body=1:15758)
    at angular.self-5592af5….js?body=1:15774
    at Scope.$eval (angular.self-5592af5….js?body=1:17026)
    at Scope.$digest (angular.self-5592af5….js?body=1:16842)
    at angular.self-5592af5….js?body=1:17065
    at completeOutstandingRequest (angular.self-5592af5….js?
    body=1:5825)
-
TypeError: Cannot read property 'url' of undefined
    at ng-token-auth.self-50017ec….js?body=1:815
    at Object.invoke (angular.self-5592af5….js?body=1:4626)
    at responseError (ng-token-auth.self-50017ec….js?body=1:813)
    at processQueue (angular.self-5592af5….js?body=1:15758)
    at angular.self-5592af5….js?body=1:15774
    at Scope.$eval (angular.self-5592af5….js?body=1:17026)
    at Scope.$digest (angular.self-5592af5….js?body=1:16842)
    at angular.self-5592af5….js?body=1:17065
    at completeOutstandingRequest (angular.self-5592af5….js?
    body=1:5825)
    at angular.self-5592af5….js?body=1:6101
-
Uncaught TypeError: Cannot read property 'validateOnPageLoad' of undefined
    at Object.addScopeMethods (ng-token-auth.self-50017ec….js?
    body=1:168)
    at Object.initialize (ng-token-auth.self-50017ec….js?body=1:109)
    at ng-token-auth.self-50017ec….js?body=1:836
    at Object.invoke (angular.self-5592af5….js?body=1:4626)
    at angular.self-5592af5….js?body=1:4434
    at forEach (angular.self-5592af5….js?body=1:322)
    at createInjector (angular.self-5592af5….js?body=1:4434)
    at doBootstrap (angular.self-5592af5….js?body=1:1711)
    at bootstrap (angular.self-5592af5….js?body=1:1732)
    at angularInit (angular.self-5592af5….js?body=1:1617)

这是我的app index和auth config:

(function(){
    'use strict';

    angular.module('MyApp', [
        'restangular',
        'ui.router',
        'templates',
        'ui.bootstrap',
        'ng-token-auth'
    ]).config(authConfig);

    authConfig.$inject = ['$authProvider'];

    /** @ngInject */
    function authConfig($authProvider) {
        $authProvider.configure({
            apiUrl: 'http://localhost:8000/'
        });
    }
    })();

更新 它似乎无法找到我的配置或getConfig不存在:

addScopeMethods: function() {
                    return c.user = this.user,
                    c.authenticate = angular.bind(this, this.authenticate),
                    c.signOut = angular.bind(this, this.signOut),
                    c.destroyAccount = angular.bind(this, this.destroyAccount),
                    c.submitRegistration = angular.bind(this, this.submitRegistration),
                    c.submitLogin = angular.bind(this, this.submitLogin),
                    c.requestPasswordReset = angular.bind(this, this.requestPasswordReset),
                    c.updatePassword = angular.bind(this, this.updatePassword),
                    c.updateAccount = angular.bind(this, this.updateAccount),
                    this.getConfig().validateOnPageLoad ? this.validateUser({
                        config: this.getSavedConfig()
                    }) : void 0
                },

它在this.getConfig().validateOnPageLoad上面的代码中失败,因为getConfig()未定义。 getSavedConfig()返回预期的配置,但是......

我在后端使用设计,所以我的理解是我只需要这样的最小配置即可开始。

请告诉我其他可以提供的信息!

1 个答案:

答案 0 :(得分:0)

我明白了!

我将配置更改为:

function authConfig($authProvider) {
    $authProvider.configure([{
        default: {
            apiUrl: 'http://localhost:8000/'
        },
        user: {
            apiUrl: 'http://localhost:8000/'
        }
    }]);
}
getConfig中的

未定义,因此return t[this.getCurrentConfigName(e)]返回'user',但我没有名为'user'的配置,因此返回了'undefined'。添加命名配置修复了此问题,因为t这里是一个对象,其中的键是配置值的名称。