P
P
Peter2016-05-11 11:17:03
JavaScript
Peter, 2016-05-11 11:17:03

Why doesn't angular show changes until hover over them?

Replaced an interesting feature. If you make changes through setTimout() in the scope:
<div ng-show="showMe">Покажи это сообщение</div>
and in the controller:

showMe = true;
setTimout(function(){
    showMe = false
}, 0)

(time in setTimout does not matter)
We get that the block will not disappear until you hover over it with the mouse.
How can this glitch be defeated and made so that he would change the view via setTimeout without hovering over it with the mouse?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nicholas, 2016-05-11
@volkov_p_v

The problem is that setTimeout calls the function asynchronously, and you need to notify Angular that the data needs to be updated using the $scope.$apply().
To avoid this, you can use the service $timeout(document link) instead of the standard window.setTimeout.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question