AngularJS $资源错误 - 类型错误:对象#< G>没有方法'推' [英] AngularJS $resource error - TypeError: Object #<g> has no method 'push'

查看:171
本文介绍了AngularJS $资源错误 - 类型错误:对象#< G>没有方法'推'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的控制文件中的以下内容:

I have the following in my controller file:

var Subject = $resource('/api/TestAccounts/:action', { applicationId: 3 }, {
   'getSelect': { method: 'GET', params: { action: 'GetSelect' } }
});

Subject.getSelect({ applicationId: 3 },
   function (resp) {
      $scope.testAccounts = resp;
      gridData = null;
   }
);

我的服务器code运行和回报:

My server code runs and returns:

[{"id":5,"name":"xxx"},{"id":6,"name":"yyy"}]

不过,我得到以下错误:

However I get the following error:

TypeError: Object #<g> has no method 'push'
    at copy (http://127.0.0.1:81/Scripts/angular.js:577:21)

有没有人有任何想法,我做错了?

Does anyone have any idea what I am doing wrong?

推荐答案

您需要设置paramater IsArray的来真正在你的资源定义,如果你正在返回从一个数组服务器。

You need to set the paramater isArray to true in your resource definition if you are returning an array from the server.

var Subject = $resource('/api/TestAccounts/:action', { applicationId: 3 }, {
  'getSelect': { method: 'GET', isArray: true, params: { action: 'GetSelect' } }
});

请参阅: AngularJS $资源API

这篇关于AngularJS $资源错误 - 类型错误:对象#&LT; G&GT;没有方法'推'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆