admin管理员组文章数量:1321445
I have the following code:
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;
});
},
and then the following function in 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;
},
When I try to do an angular.copy I get a message saying:
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 pleteRequest (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)
Does anyone have an idea of how I can make a copy of the data returned. Note that this data es back from ngResource. Also this seems different from the other problems that I find on Stackoverflow related to: TypeError: Object # has no method 'push' questions. With this problem I am getting the data back okay. It goes into $scope.grid.data but then gives me an error when trying to angular.copy the data.
I have the following code:
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;
});
},
and then the following function in 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;
},
When I try to do an angular.copy I get a message saying:
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 pleteRequest (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)
Does anyone have an idea of how I can make a copy of the data returned. Note that this data es back from ngResource. Also this seems different from the other problems that I find on Stackoverflow related to: TypeError: Object # has no method 'push' questions. With this problem I am getting the data back okay. It goes into $scope.grid.data but then gives me an error when trying to angular.copy the data.
Share Improve this question edited Jul 22, 2013 at 9:36 asked Jul 22, 2013 at 9:29 user1943020user19430201 Answer
Reset to default 9Take a close look at angular.copy
doc:
destination(optional) – {(Object|Array)=} – Destination into which the source is copied. If provided, must be of the same type as source.
The result you got back from service call is probably an array; you however initialized $scope.grid.originalData
as an object or something else other than array, so you got this type error.
Try to figure out what type the result
is, and make $scope.grid.originalData
the same type before calling angular.copy
.
本文标签: javascriptError when using angularcopy() to copy data returned from ngResourceStack Overflow
版权声明:本文标题:javascript - Error when using angular.copy() to copy data returned from ngResource - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742100333a2420772.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论