2014-12-25 234 views
0
$scope.logout = function() { 
    //var auth_token = $cookieStore.get('auth_token'); 
    Auth.delete({ 
     'auth_token': $cookieStore.get('auth_token') 
    }, function(data){ 
     $scope.isLoggedIn = false; 
     $cookieStore.remove('auth_token'); 
    }); 

當這個叫它給了我一個錯誤:AngularJS代碼返回錯誤?

Error: [$resource:badcfg] http://errors.angularjs.org/1.2.27/$resource/badcfg?p0=object&p1=array 
z/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:6:450 
t/</f[d]/q<@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular-resource.min.js:8:1 
De/e/l.promise.then/[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:101:87 
De/e/l.promise.then/[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:101:87 
De/f/<.then/<@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:102:259 
Yd/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:113:28 
Yd/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:110:109 
Yd/this.$get</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:113:360 
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:72:452 
[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:77:463 
ye/</[email protected]://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:79:24 

http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js 
Line 92 
+0

http://errors.angularjs.org/1.2.27/$resource/badcfg?p0=object&p1=array。如果您轉到錯誤中提供的網址,則說明問題所在。您的$資源被配置爲返回一個數組,但服務器正在發送一個對象,反之亦然。更改您的資源配置,有一個isArray屬性,您可以相應地設置爲true或false。 –

+0

使用非縮小版角度來了解錯誤細節 – harishr

回答

1

它是一個常見的問題。資源模型的delete方法期望一個json響應,它必須是一個對象,但是你的服務器以數組格式返回json數據。所以,你有兩個選擇要麼改變你的服務器代碼響應JSON對象數據或更改資源模型是這樣的:

var Auth = $resource('/your-server-url', {}, { 
    delete: { 
     isArray: false 
    } 
}); 

希望這有助於!

感謝,
SA