I
I
imelos2015-08-04 03:46:00
Angular
imelos, 2015-08-04 03:46:00

How to prevent ngModelController.$viewValue from changing when the model changes?

$scope.model = '';

<input type="radio" value="radiovalue" ng-model="model"/>
<input type="radio" value="radiovalue2" ng-model="model"/>
<input type="text" ng-model="model"/>

When a radio input is selected, the model will receive the values ​​of the element's value attribute. Accordingly, this value will be displayed in the text input.
How to prevent this behavior (leave the possibility of only "setting" the model)?
Alternatively, you can use ngModelController.$formatters. but you will have to redefine viewValue every time you change the model, maybe someone knows a more beautiful solution? .

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alex, 2015-08-04
@streetflush

<input type="radio" value="radiovalue" ng-model="model"/>
<input type="radio" value="radiovalue2" ng-model="model"/>
<input type="text" value="{{model}}"/>
<pre>{{model}}</pre>

Or simply disabled at the field to prescribe so that it could not be changed
If I understand you correctly.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question