i'm having problem when update object, it's creating duplicate of instance (singleorder) in model, instead of updating exisiting one. can't clear whole $scope , reload, i'm updating part of object.
here's save function:
$scope.savedetails = function(singleorder, data, status) { ordersservice.updateorders(singleorder.order) .success(function(data, status) { angular.extend(singleorder, data); }) }
where singleorder relates instance of main orderdetails object, used in ng-repeat
<div ng-repeat="singleorder in orderdetails track $index">
here's function called in ordersservice, if helps:
getdata.updateorders = function(data){ var url = '/service/rest/orders'; return $http.post(url, data) };
thanks can offer.
update: i've tried messing around track by
, received following results:
<div ng-repeat="singleorder in orderdetails track $index">
saves content fine, creates duplicate order on dom.
<div ng-repeat="singleorder in orderdetails track singleorder.order.id">
works each order has unique id. can save fine , doesn't create duplicate in dom, duplicates in repeater not allowed in console.
confused why happening. ideas welcome!
angular.extend() returns destination object, maybe this
ordersservice.updateorders(singleorder.order) .success(function(data, status) { singleorder = angular.extend(singleorder, data); })
but in opinion better when server returns whole object client needs. code easier.