我的控制器文件中有以下内容:
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; } );
我的服务器代码运行并返回:
[{"id":5,"name":"xxx"},{"id":6,"name":"yyy"}]
但是我收到以下错误:
TypeError: Object #<g> has no method 'push' at copy (http://127.0.0.1:81/Scripts/angular.js:577:21)
有人有什么想法我做错了吗?
如果从服务器返回数组,则需要在资源定义中将参数setArray设置为true。
var Subject = $resource('/api/TestAccounts/:action',{ 'getSelect': { method: 'GET',isArray: true,params: { action: 'GetSelect' } } });