如何编辑[(ngModel)]显示的值? [英] How to edit the value displayed by [(ngModel)]?

查看:267
本文介绍了如何编辑[(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}}" />

如何显示该值除以100?

How can I display that value divided by 100 ?

推荐答案

使用[()]的简化语法.

<input type=text [(ngModel)]="myValue">

等同于

<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.

这篇关于如何编辑[(ngModel)]显示的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆