$timeout() doesn't update the model
$timeout() doesn't update the model in this demo while $apply() does.
http://plunker.no.de/edit/PV2Dzv?live=preview
Really weird behaviour.
$timeout() has a third boolean parameter to specify whether it should invoke an $apply.
http://docs.angularjs.org/api/ng.$timeout
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.
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.
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.
Bug in the compiler, I take care of it.