2014-02-06 44 views
3

我有這樣的代碼:與angularjs和restangular發現錯誤

MyService.one($routeParams.wuid).doGET('test').then(function(e){ 
    alert('ok'); 
}, function errorCallback(response){ 
    alert('error'); 
}); 

它調用的API我管理,但只有警報(「OK」)的作品,404迴應的情況下,回調ISN沒有叫我在我的控制檯中有一個angularjs錯誤。

Error: c is undefined this.$get</e/A/[email protected]://localhost:8888/client/app/js/libs/restangular.min.js:8 Ad/e/k.promise.then/[email protected]://localhost:8888/client/app/js/libs/angular.min.js:92 Ad/g/<.then/<@http://localhost:8888/client/app/js/libs/angular.min.js:94 Bd/this.$get</[email protected]://localhost:8888/client/app/js/libs/angular.min.js:102 Bd/this.$get</[email protected]://localhost:8888/client/app/js/libs/angular.min.js:100 Bd/this.$get</[email protected]://localhost:8888/client/app/js/libs/angular.min.js:103 [email protected]://localhost:8888/client/app/js/libs/angular.min.js:67 [email protected]://localhost:8888/client/app/js/libs/angular.min.js:71 pd/</[email protected]://localhost:8888/client/app/js/libs/angular.min.js:72 

我不理解,因爲the official doc說:

我如何處理錯誤?

錯誤可以檢查當時的第二個參數。

Restangular.all( 「帳戶」)的GetList(),然後(函數(){
的console.log( 「一切正常」);}。。,功能(響應){的console.log(「錯誤 與狀態碼「,response.status);});

我在哪裏錯了?

+0

完美工作在我的代碼。創建一個顯示錯誤的蹦牀或小提琴,我相信有人會協助。 – Beyers

+0

感謝您的回覆。我發佈了一段錯誤的代碼,我糾正了。它是一個doGet()而不是一個get(),沒有別的改變 – billyJoe

回答

0

我找到了一種方法here 的問題來自於我的攔截,我開始對昨天沒有完成:

myApp.run(function($http, $rootScope, $location, sessionService){ 
    $rootScope.$on('$routeChangeStart', function(event, next, current){ 
     if(!sessionService.isLogged() && next.requireLogin){ 
      $location.path("/login"); 
     } 

     if(sessionService.isLogged()){ 
      if(next.controller !== "LoginCtrl"){ 
       $http.defaults.headers.common['Authorization'] = 'Bearer ' + sessionService.getToken(); 
      } 
     } 
    }); 

}); 

當我刪除這個攔截器,我可以看到我的警報(「錯誤」)。我想我必須修復/結束攔截器和evertything將正常工作。