【问题标题】:How to identify specific input field and set its value to empty如何识别特定输入字段并将其值设置为空
【发布时间】:2016-12-12 20:56:06
【问题描述】:

我有这个 Angular 模板,有两个输入字段,我想在两个字段之一中识别特定输入字段并将其值设置为空而不是两者

<input type='text'  [value]='title'>
<input type = 'text' [value]='title'>
<button (click)="title = ''">Clear</button>

【问题讨论】:

  • 不确定是什么问题。如果您将两个输入绑定到同一个属性,那么没关系。如果您将title 设置为新值,所有绑定到title 的元素都将被更新。也许您实际上想将它们绑定到不同的属性。

标签: javascript html dom angular dom-events


【解决方案1】:
<input #input1 type='text'  [value]='title'>
<input #input2type = 'text' [value]='title'>
<button (click)="input1.value = ''; input2.value = ''">Clear</button>

最好是更新模型,尽管你在问题中有它

<input #input1 type='text'  [value]='title'>
<input #input2type = 'text' [value]='title'>
<button (click)="title = ''">Clear</button>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-07
    • 2015-07-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-09-02
    相关资源
    最近更新 更多