You are looking at the correct documentation, but it might just be that you’re a little confused. The $modelValue
and $viewValue
have one distinct difference. It is this:
As you already noted above:
$viewValue:
Actual string (or Object) value in the view.
$modelValue:
The value in the model, that the control is bound to.
I’m going to assume that your ngModel is referring to an <input />
element…? So your <input>
has a string value that it displays to the user, right? But the actual model might be some other version of that string. For example, the input might be showing the string '200'
but the <input type="number">
(for example) will actually contain a model value of 200
as an integer. So the string representation that you “view” in the <input>
is the ngModel.$viewValue
and the numeric representation will be the ngModel.$modelValue
.
Another example would be a <input type="date">
where the $viewValue
would be something like Jan 01, 2000
and the $modelValue
would be an actual javascript Date
object that represents that date string. Does that make sense?
I hope that answers your question.