0

I am working on array with javascript. I am able to add the array by using push. However, I am not sure how to edit an items. As you can see in this link below , I have the push method for my add item, which is working fine. But what should I do with my edit button if I want to change replacing the old item with the new one? Do I need to use foreach to do it? Help will be appreciated jsfiddle.net/hin123/tcVhN/127/

I am stuck with this part $scope.saveDetail = function (data) { //angular.foreach }

Big Ticket
  • 503
  • 3
  • 5
  • 17
  • Need to post your code. There's a reason you couldn't use a fiddle link without code...questions need to be self contained for several reasons....number one is for people to be able see it without having to leave the site.....then add the fiddle link – charlietfl Jul 26 '15 at 04:17
  • You need to find the index of object you want to edit .. – Rayon Jul 26 '15 at 04:17
  • Hi sorry, I have posted my link, @RayonDabre, can you help me through with the link that I just updated? – Big Ticket Jul 26 '15 at 04:22
  • Hi Madness, It is in the controller, under the onItemDelete – Big Ticket Jul 26 '15 at 04:25
  • Major issue in your `ng-model` binding... always have a dot in ng-model ....must read: http://stackoverflow.com/questions/17606936/angularjs-dot-in-ng-model. Your edit form is broken due to this issue. A single object in the scope to fix this issue also makes all the form data simpler to code in controller – charlietfl Jul 26 '15 at 04:55

1 Answers1

0

You can use Array.prototype.splice() to insert items, eg.

    $scope.tempData.splice($scope.tempData.indexOf(oldData), 1, newData);
mofojed
  • 1,342
  • 9
  • 11