Q
Q
qblook2016-12-03 05:25:55
JavaScript
qblook, 2016-12-03 05:25:55

Why doesn't AngularJS always remove DOM elements that are removed from $scope?

Hello,
There is ng-repeat in the view that renders the list according to the view data array stored in $scope:

<tr ng-repeat="slot in model.slots[model.value1][model.value2]" ...

model actually = $scope.model in the view controller.
On a certain event, data is loaded from the server and model.value1 / model.value2 change their values ​​- as a result, the list should be displayed (and displayed) by another means of automatic response of AngularJS to changes in these variables.
Problem:
Periodically (not always, but very often) AngularJS, when these variables are changed, does not delete the old list, but displays it under the new one - as a result, there are two lists on the page at once: according to the old state of the model.value1, model.value2 variables and according to the new one.
1. There are no errors in the console;
2. Manual launch of $scope.$apply after changing the variables does not give any result. $digest is already in progress and an error is thrown to the console;
3. They tried to zero/delete the old array - it's useless: the DOM still displays the list elements that are no longer in the model;
4. Layout is ok;
5. Data in arrays is also ok;
PS: It feels like AngularJS is "losing" DOM ​​tree elements, assuming the render area is empty and running ng-repeat on tr without deleting the old elements.
PSS: tr is extended by its own directive, which is already responsible for drawing the array element
. What could be the problem?
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

3 answer(s)
P
Philipp, 2016-12-03
@zoonman

To get started, look at tr.
You can also try $scope.applyAsync()

N
Nicholas, 2016-12-03
@healqq

Try putting track by in ng-repeat.
Well, more information is needed, for example, a part of the code that updates the models.

_
_ _, 2016-12-03
@AMar4enko

Show me your tr directive. Use track by

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question