如何识别特定输入字段并将其值设置为空

时间:2016-08-06 16:09:54

标签: javascript html dom angular dom-events

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

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

1 个答案:

答案 0 :(得分:0)

<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>
相关问题