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

How to identify specific input field and set its value to empty

本文关键字:字段 设置 输入 何识别 识别      更新时间:2023-09-26

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

<input type='text'  [value]='title'>
<input type = 'text' [value]='title'>
<button (click)="title = ''">Clear</button>
<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>