【发布时间】:2021-05-13 09:05:31
【问题描述】:
我有一个输入,在保存之前,我希望输入显示 AB 的值,然后我用名称计数保存这个值,保存后,我运行 fucntionA,并将计数设置为 5。但我是结果不断得到 NaN,我还尝试在 html 输入标记中添加 type="number",然后它只在输入字段内显示空字符串。
html文件
<input type="number" [readonly]="true" class="abc" name="account" id="acc" [value]="A-B" [(ngModel)]="count"/>
ts 文件
functionA(){
this.count = 5;
console.log(this.count); //5
console.log(this.A - this.B); //5
}
【问题讨论】:
-
[(ngModel)]是双向绑定,所以你根本不需要[value]="A-B"。该值将始终为this.count -
@JeremyThille 但在我保存之前,我想显示值 A-B,而 A 是一个输入值,所以它会使计数动态化。
-
您不能有 both 将值设置为
count的双向数据绑定,以及将值设置为 @ 的单向数据绑定987654327@同时。这是简单的常识。恐怕你必须找到另一个设置。
标签: javascript typescript data-binding angular8 two-way-binding