我有以下代码:
getContents: function ($scope, entityType, action, subjectId, contentTypeId, contentStatusId) {
entityService.getContents(entityType, action, subjectId, contentTypeId, contentStatusId)
.then(function (result) {
$scope.grid.data = result;
angular.copy($scope.grid.data, $scope.grid.originalData);
$scope.grid.newButtonEnabled = true;
}, function (result) {
alert("Error: No data returned");
$scope.grid.newButtonEnabled = false;
});
},
然后entityService中的以下函数:
getContents: function (entityType, action, subjectId, contentTypeId, contentStatusId) {
var deferred = $q.defer();
EntityResource.getEntities({ entityType: entityType, subjectId: subjectId, contentTypeId: contentTypeId, contentStatusId: contentStatusId },
function (resp) {
deferred.resolve(resp);
}
);
return deferred.promise;
},
当我尝试执行 angular.copy 时,我收到一条消息:
TypeError: Object #<Object> has no method 'push'
at Object.copy (http://127.0.0.1:81/Scripts/angular.js:600:21)
at factory.getContents.entityService.getContents.then.$scope.grid.newButtonEnabled (http://127.0.0.1:81/Content/app/admin/services/grid-service.js:303:29)
at deferred.promise.then.wrappedCallback (http://127.0.0.1:81/Scripts/angular.js:7303:59)
at ref.then (http://127.0.0.1:81/Scripts/angular.js:7340:26)
at Object.$get.Scope.$eval (http://127.0.0.1:81/Scripts/angular.js:8685:28)
at Object.$get.Scope.$digest (http://127.0.0.1:81/Scripts/angular.js:8548:23)
at Object.$get.Scope.$apply (http://127.0.0.1:81/Scripts/angular.js:8771:24)
at done (http://127.0.0.1:81/Scripts/angular.js:10004:20)
at completeRequest (http://127.0.0.1:81/Scripts/angular.js:10180:7)
at XMLHttpRequest.xhr.onreadystatechange (http://127.0.0.1:81/Scripts/angular.js:10144:11)
有谁知道我如何制作返回数据的副本。请注意,此数据来自 ngResource。此外,这似乎与我在 Stackoverflow 上发现的其他问题不同:TypeError: Object # has no method 'push' questions。有了这个问题,我可以恢复数据。它进入 $scope.grid.data 但在尝试 angular.copy 数据时给我一个错误。