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

feat(ngModel): add public $setModelValue fn to programmatically update model #11128

Closed
@tdakhla

Description

@tdakhla

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions