setViewValue in directive on input not updating actual visible input value setViewValue in directive on input not updating actual visible input value angularjs angularjs

setViewValue in directive on input not updating actual visible input value


You need to call ngModel.$render() to have the viewvalue change reflected in the input. There is no watch created on $viewValue so that changes are automatically reflected.

   function setAnotherValue() {        ngModel.$setViewValue("I'm a new value of the model. I've been set using the setViewValue method");        ngModel.$render();    }

Plnkr

Default implementation of $render does this:-

 element.val(ctrl.$isEmpty(ctrl.$viewValue) ? '' : ctrl.$viewValue);

However you can override and customize your implementation for $render as well..


try scope.$apply() to invoke change on model since you're liking changing model outside of scope where ngModel was inited