Angular.js: bug(ngModel): `$setViewValue` doesn't call `$$debounceViewValue` when called with the appropriate `trigger`

Created on 8 Jul 2016  ·  3Comments  ·  Source: angular/angular.js

Do you want to request a _feature_ or report a _bug_?
Bug.

What is the current behavior?
Calling NgModelController#$setViewValue(value, trigger) will call $$debounceViewValue() _only_ if there is no ngModelOptions or ngModelOptions#updateOnDefault is true.
See here.

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via https://plnkr.co or similar (template: http://plnkr.co/edit/tpl:yBpEi4).
Demo
Clicking both buttons, I would expect both NgModelControllers to get updated.
The one with {updateOn: 'blur'} doesn't :disappointed:

What is the expected behavior?
Calling NgModelController#$setViewValue(value, trigger) will also call $$debounceViewValue() if ngModelOptions#updateOn includes trigger.

What is the motivation / use case for changing the behavior?
To make it work as expected :grin:

Which versions of Angular, and which browser / OS are affected by this issue? Did this work in previous versions of Angular? Please also test with the latest stable and snapshot (https://code.angularjs.org/snapshot/) versions.
Only tried on 1.5.7, but it should affect many versions back.

Other information (e.g. stacktraces, related issues, suggestions how to fix)
No :confused:

forms low investigation broken expected use bug

Most helpful comment

BTW, this was a by-product of a discussion with @jeserkin on gitter and he expressed interest in taking a stab at it. (Shamelessly) saving it for him :stuck_out_tongue:

All 3 comments

That definitely doesn't seem quite right. What is weird is that if you click the second then the first button, all four are updated!

The reason it works if you press the first button after you have pressed the second one, is because of the digest that get triggered by the button click. There is an ngModel watch-action executed per digest, that will sync the values (see here).

The problem is when this happens outside of a digest. And even from inside a digest, the values are not updated synchronously as happens in the first case (with updateOnDefault === true).

BTW, this was a by-product of a discussion with @jeserkin on gitter and he expressed interest in taking a stab at it. (Shamelessly) saving it for him :stuck_out_tongue:

Was this page helpful?
0 / 5 - 0 ratings