[英]How to edit the value displayed by [(ngModel)]?
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 ? 如何显示该值除以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. 这意味着您可以分别控制希望数据如何流入以及事件如何流出。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.