feat(ngModel): add public $setModelValue fn to programmatically update model #11128
Description
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:
this.$setModelValue = function(value) {
ngModelSet($scope, value);
};
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.