Answer the question
In order to leave comments, you need to log in
What is the correct way to update an array element?
Hey!
I'll start at the end of the question. You only need to update those elements of the array that have changed. You can not update the entire array!
[{"id":87510,"name":"1","date":1506983543"}{"id":87512,"name":"2","date":1506983543"}]
Controller:
$scope.getData = function() {
$http.get('/api/arr/', {
cache: true
}).then(successCallback, errorCallback);
};
function successCallback(response) {
if ($scope.arr== null) {
$scope.arr= [];
angular.merge($scope.arr, response.data);
}
// но что делать, если нужно обновиться?
//пытался делать так:
for (var i = 0; i < $scope.arr.length; i++) {
if ($scope.arr[i].name!=response.data[i].name) {
$scope.arr[i].name= response.data[i].name
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question