Answer the question
In order to leave comments, you need to log in
How to update data in ngRepeat via ajax in AngularJS without redrawing the DOM?
Hello!
I want to update the list of incoming orders on the current page by timer. I understand that it's cooler to do this through web sockets, but that's later :) For now, I want to.
The data is output through ngRepeat with track by - I read in the docs that in this way the angular knows the exact element identifier, and does not invent it itself, and, as I understand it, when the data array is updated - if the identifiers match, then the DOM of such elements will not be touched. But everything is wrong with me - everything is redrawn anyway :( The data in the controller is updated like this:
$timeout(function () {
self.orders = Order.query();
}, 30000);
<tr data-ng-repeat="order in $ctrl.orders track by order.id">
...
Answer the question
In order to leave comments, you need to log in
As far as I understand, what you wrote about the rerender will work in the case when an array is pushed / popped. And when the array is replaced by a completely different one, a full re-render occurs.
If you are redrawing, then the identifiers (order.id) do not match, check that there are identifiers and they are of a simple type (number/string).
If most of the identifiers do not match, then it is more efficient to use track by $index.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question