0

I am trying to show a loading indicator whenever a user clicks the save button. When the button is clicked, the state changes successfully, but reverting back the value of the loading property on scope to the false state doesn't update the UI.

Is it something i'm doing wrong with scope properties, or is this a flaw with angular?

Here's my jsBin: http://jsbin.com/xafexorope/2/edit?html,output

1 Answer 1

2

The reason why it doesnt work is because Angular's internal dirty-checking loop is not fired. It's because you use a standard setTimeout. Instead of that, either manually call $scope.$apply() at the end of your setTimeout callback, or better, use the angular wrapper $timeout.

Here is your updated jsbin: http://jsbin.com/devuhovaxa/3/edit

Additionally here the docs for $timeout: https://docs.angularjs.org/api/ng/service/$timeout

Sign up to request clarification or add additional context in comments.

3 Comments

In my actual application its in the callback for a UserApp.io ajax request, i just used a timeout so the example would work. That being said, I used $scope.$apply there, and it worked! Thanks!
Any useful documentation you would recommend regarding this particular issue? Specifically the "dirty-checking" loop and the $scope.$apply?
Not sure if I understand what exactly you are searching for but those posts are pretty nice: sitepoint.com/understanding-angulars-apply-digest and this one benlesh.com/2013/08/angularjs-watch-digest-and-apply-oh-my.html

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.