2017-06-13 40 views
1

我有一個AngularJs + Ruby on Rails應用程序,我試圖集成ng-token-auth,但是當我的應用程序加載時出現以下警告和錯誤,防止應用程序從實際加載: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) 

這裏是我的應用程序的索引,並權威性配置:

(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/' 
     }); 
    } 
    })(); 

UPDATE 看來,它要麼無法找到我的配置或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 
       }, 

由於getConfig()未定義,因此在this.getConfig().validateOnPageLoad上的代碼失敗。 getSavedConfig()返回預期的配置,但是......


我使用的設計在後端,所以我的理解是,我只需要一個很小的配置這樣上手。

請讓我知道我可以提供什麼其他信息!

回答

0

我想通了!

我改變了我的config來:

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

getConfig e爲不確定的,所以return t[this.getCurrentConfigName(e)]返航「用戶」,但我沒有返回配置命名爲「用戶」,所以「未定義」。添加一個命名的配置解決了這個問題,因爲t這裏是一個帶有配置值名稱的對象。