我正在尝试获取一个表单,其中字段 Exchange 已填充为"HELLO"。在 HTML 中使用value
不起作用,并且该字段显示为空白。
我尝试添加autocomplete=off
,但这也不起作用。
<div class="form-group">
<label for="AccountRef">Account Ref</label>
<div class="input-group">
<input type="text" id="accountref" name="accountref" [(ngModel)]="newAccount.accountRef">
<div class="input-group-append"></div>
</div>
<label for="Client">Client Name</label>
<div class="input-group">
<input type="text" id="client" name="client" [(ngModel)]="newAccount.client">
<div class="input-group-append"></div>
</div>
<label for="Exchange">Exchange</label>
<div class="input-group">
<input type="text" id="exchange" name="exchange" value ="HELLO" autocomplete="off" [(ngModel)]="newAccount.exchange">
<div class="input-group-append"></div>
</div>
</div>
因为您使用的是双向绑定[(ngModel)]=newAccount.exchange
您需要使用 newAccout.exchange 填充值
所以在你的ts/js文件中给出默认值试试这个: newAccout.exchange="Hello"
对我有用。尝试另一个浏览器或更好的另一个IDE-Sublime,Webstorm,Visual Code等。
@Ashok所说,您需要填充">newAccount.exchange",但是如果您只想填充值html而不填充[(ngModel(],则需要1路数据绑定。
<input type="text" id="exchange" name="exchange" [value]="newAccount.exchange" autocomplete="off">