Skip to content
This repository has been archived by the owner on Apr 12, 2024. It is now read-only.

$timeout() doesn't update the model #1272

Closed
ghost opened this issue Aug 16, 2012 · 5 comments
Closed

$timeout() doesn't update the model #1272

ghost opened this issue Aug 16, 2012 · 5 comments

Comments

@ghost
Copy link

ghost commented Aug 16, 2012

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

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

Really weird behaviour.

@leefernandes
Copy link
Contributor

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

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

@mhevery
Copy link
Contributor

mhevery commented Aug 17, 2012

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 notifications@github.comwrote:

$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//issues/1272#issuecomment-7835530.

@symblify
Copy link

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
Copy link

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.

@ghost ghost assigned vojtajina Sep 13, 2012
@vojtajina
Copy link
Contributor

Bug in the compiler, I take care of it.

vojtajina added a commit to vojtajina/angular.js that referenced this issue Sep 13, 2012
This was really corner case:
Watcher needs to return changed value, to notify that model might have changed and one more $digest cycle needs to be performed.

The watcher, that takes care of reference binding into an isolate scope ("="), did not return changed value, if the change was from the isolate scope to the parent.

If any other watcher returned change, it worked fine, as this change caused re-digest.

Closes angular#1272
vojtajina added a commit that referenced this issue Sep 22, 2012
This was really corner case:
Watcher needs to return changed value, to notify that model might have changed and one more $digest cycle needs to be performed.

The watcher, that takes care of reference binding into an isolate scope ("="), did not return changed value, if the change was from the isolate scope to the parent.

If any other watcher returned change, it worked fine, as this change caused re-digest.

Closes #1272
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants