angular.js icon indicating copy to clipboard operation
angular.js copied to clipboard

$timeout() doesn't update the model

Open ghost opened this issue 14 years ago • 5 comments

$timeout() doesn't update the model in this demo while $apply() does.

http://plunker.no.de/edit/PV2Dzv?live=preview

Really weird behaviour.

ghost avatar Aug 16 '12 18:08 ghost

$timeout() has a third boolean parameter to specify whether it should invoke an $apply.

http://docs.angularjs.org/api/ng.$timeout

leefernandes avatar Aug 17 '12 21:08 leefernandes

Actually difficult value is true, so it should work, but regardless of what you put there it does not. I think it may be a race condition, but have not looked into it deep enough.

On Fri, Aug 17, 2012 at 2:22 PM, ItsLeeOwen [email protected]:

$timeout() has a third boolean parameter to specify whether it should invoke an $apply. default value is false.

http://docs.angularjs.org/api/ng.$timeout

— Reply to this email directly or view it on GitHubhttps://github.com/angular/angular.js/issues/1272#issuecomment-7835530.

mhevery avatar Aug 17 '12 21:08 mhevery

As can be seen here

https://github.com/angular/angular.js/blob/master/src/ng/timeout.js#L49

$timeout calls $apply on the root scope, which might explain why the age isn't updated.

symblify avatar Aug 21 '12 21:08 symblify

Ignore my last comment, of course running $apply on the root scope should update all the child scopes too.

Interestingly if you add {{age}} to the template in the directive, it seems to work okay. Alternatively adding scope.$watch('age'); to the link function makes it work also.

I think the problem might be that because age isn't used in the template, no watch is set up and so updating it doesn't do anything.

symblify avatar Aug 22 '12 00:08 symblify

Bug in the compiler, I take care of it.

vojtajina avatar Sep 13 '12 08:09 vojtajina