I am receiving a value, that I display to the user in a text field.
The idea is for him to be able to edit this value, and then send it back.
In the case of money, let's say I store the amount in cents, but I want to display it in dollars. Here is an idea of the code I have that display the value I receive :
<input type="text" [(ngModel)]="myValue" value="{{myValue}}" />
I tried this without success :
<input type="text" [(ngModel)]="myValue/100" value="{{myValue/100}}" />
How can I display that value divided by 100 ?
Use the desugared syntax of [()]
.
<input type=text [(ngModel)]="myValue">
is equivalent to
<input type=text [ngModel]="myValue" (ngModelChange)="myValue = $event">
This means that you can separately control how do you want data to flow in, and how should events flow out.
来源:https://stackoverflow.com/questions/45832439/how-to-edit-the-value-displayed-by-ngmodel