I am managing an array called $scope.notys
in my controller and using ng-repeat
:
<li ng-repeat="x in notys" class="item js-item">
...
To add data to the array from my controller, I use this method:
$scope.notys.push(data);
Each piece of data
includes a unique id property called data.id
The question I have is how can I update or replace an object where the id property matches with the last data.id
received from an ajax call?
So basically, I need to follow these steps:
Retrieve
data
from the ajax callWith the new
data.id
, I need to check if there is already an object in$scope.notys
with the same idIf an object with that id already exists, then replace it with the latest data. If not, simply add the new data by using
push