javascript - Error when using angular.copy() to copy data returned from ngResource -


i have 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 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 try angular.copy message saying:

typeerror: object #<object> has no method 'push'     @ object.copy (http://127.0.0.1:81/scripts/angular.js:600:21)     @ factory.getcontents.entityservice.getcontents.then.$scope.grid.newbuttonenabled (http://127.0.0.1:81/content/app/admin/services/grid-service.js:303:29)     @ deferred.promise.then.wrappedcallback (http://127.0.0.1:81/scripts/angular.js:7303:59)     @ ref.then (http://127.0.0.1:81/scripts/angular.js:7340:26)     @ object.$get.scope.$eval (http://127.0.0.1:81/scripts/angular.js:8685:28)     @ object.$get.scope.$digest (http://127.0.0.1:81/scripts/angular.js:8548:23)     @ object.$get.scope.$apply (http://127.0.0.1:81/scripts/angular.js:8771:24)     @ done (http://127.0.0.1:81/scripts/angular.js:10004:20)     @ completerequest (http://127.0.0.1:81/scripts/angular.js:10180:7)     @ xmlhttprequest.xhr.onreadystatechange (http://127.0.0.1:81/scripts/angular.js:10144:11)  

does have idea of how can make copy of data returned. note data comes ngresource. seems different other problems find on stackoverflow related to: typeerror: object # has no method 'push' questions. problem getting data okay. goes $scope.grid.data gives me error when trying angular.copy data.

take close @ angular.copy doc:

destination(optional) – {(object|array)=} – destination source copied. if provided, must of same type source.

the result got service call array; initialized $scope.grid.originaldata object or else other array, got type error.

try figure out type result is, , make $scope.grid.originaldata same type before calling angular.copy.


Comments

Popular posts from this blog

html5 - What is breaking my page when printing? -

c# - must be a non-abstract type with a public parameterless constructor in redis -

ajax - PHP/JSON Login script (Twitter style) not setting sessions -