You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
In regards to my workaround in #11090 (comment), it would be nice to have a $setModelValue fn in NgModelController which would programmatically update the model. Instead of having to inject in $parse to my directive, do $parse(attrs.ngModel).assign(scope, newValue), etc, (I've seen code like this in several places, and I've used it a lot in my directives), there should be a public fn to do that work.
The code in NgModelController should be as easy as:
Or, if all the $viewChangeListeners need to get executed, then perhaps open up this.$$writeModelToScope by changing it so it accepts a model value param, and rename it to this.$setModelValue (and doing the handful of refactors). I think having $setModelValue would be a nice addition to the ngModel API.
The text was updated successfully, but these errors were encountered:
tdakhla
changed the title
feat(ngModel): add public $setModelValue fn to programmatically update mdoel
feat(ngModel): add public $setModelValue fn to programmatically update model
Feb 22, 2015
Customizing when / how the model is set to scope is definitely planned. Btw, $setModelValue is a bit confusing as there's also the $modelValue property on ngModel, and I would expect that this is set from this function.
Setting the scope model from inside the ngModel controller so that it runs the model > view pipeline again is not good practice. There might be edge cases where it is necessary, but I'd rather have devs use parse and assign in this case, then expose a function on the ngModelController that does it.
For the simple case where you need to re-run the formatters on the modelValue, there will be a function in 1.6.7: 1451948
In regards to my workaround in #11090 (comment), it would be nice to have a
$setModelValue
fn inNgModelController
which would programmatically update the model. Instead of having to inject in$parse
to my directive, do$parse(attrs.ngModel).assign(scope, newValue)
, etc, (I've seen code like this in several places, and I've used it a lot in my directives), there should be a public fn to do that work.The code in NgModelController should be as easy as:
Or, if all the
$viewChangeListeners
need to get executed, then perhaps open upthis.$$writeModelToScope
by changing it so it accepts a model value param, and rename it tothis.$setModelValue
(and doing the handful of refactors). I think having$setModelValue
would be a nice addition to the ngModel API.The text was updated successfully, but these errors were encountered: