In angular 1.2 I need to be able to update the $modelValue
without affecting the $viewValue
. I want the internal value to be one value, while what the user sees to be another. The problem I am having is setting the $modelValue
ends up setting the $viewValue
on the next digest. My current work-around is using $timeout
to set the $viewValue
in the next digest.
//...
link: function(scope, elem, attrs, ctrl) {
//...
var setter = $parse(attrs.ngModel).assign;
scope.$watch(attrs.otherValue, function(){
var viewValue = ctrl.$viewValue;
setter(scope, validate()); // validate returns undefined or value if valid
$timeout(function(){
if(ctrl.$viewValue !== viewValue){
ctrl.$viewValue = viewValue;
ctrl.$render();
}
});
});
//...
}
//...
Basically, I want to set the internal value of one with when another field changes in Angular 1.2
Fiddle (with ugly $timeout
workaround): http://jsfiddle.net/TheSharpieOne/q1s7Lf7z/1/
TL;DR
Setting $modelValue
outside of $parser
/$formatter
pipelines changes $viewValue
, where I am wanted it to only change $modelValue
(the internal value).