Yarin Yarin - 1 year ago 239
AngularJS Question

Angular model doesn't update when changing input programmatically

I have a text input bound to a model value, but I can't figure out how to change the input value programmatically and have the change propagate to the model.

I understand that because I'm updating the value external to the angular scope that I need to explicitly call

, but it's not working.


<input id="test_input" ng-model="test_value">


$scope.test_value = 'abc'; // starting value


-> 'abc';

Answer Source

ngModel listens for "input" event, so you need to trigger that event after setting the value: