AngularJS代码回放错误?

时间:2014-12-25 08:16:10

标签: javascript angularjs

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

当这称它给我一个错误时:

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/J@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:101:87
De/e/l.promise.then/J@http://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</h.prototype.$eval@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:113:28
Yd/this.$get</h.prototype.$digest@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:110:109
Yd/this.$get</h.prototype.$apply@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:113:360
m@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:72:452
w@http://ajax.googleapis.com/ajax/libs/angularjs/1.2.27/angular.min.js:77:463
ye/</B.onreadystatechange@http://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

1 个答案:

答案 0 :(得分:1)

这是一个常见的问题。资源模型的delete方法期望json响应必须是对象,但是服务器以数组格式返回json数据。因此,您有两个选项可以更改服务器代码以响应json对象数据,也可以更改资源模型,如:

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

希望这有帮助!

谢谢,
SA