HTML";“价值”;使用角形时未预先填充表单的字段
我正在尝试获取一个表单,其中字段交换已经填充为“HELLO”。在HTML中使用HTML";“价值”;使用角形时未预先填充表单的字段,html,angular,forms,Html,Angular,Forms,我正在尝试获取一个表单,其中字段交换已经填充为“HELLO”。在HTML中使用value无效,字段显示为空白 我尝试添加autocomplete=off,但也不起作用 <div class="form-group"> <label for="AccountRef">Account Ref</label> <div class="input-group"> <input type="te
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、可视代码等。正如@Ashok所说,您需要填充“newAccount.exchange”,但如果您只想填充值html而不使用[(ngModel)],则需要单向数据绑定
据我所知,在“value”之后还有额外的“space”。你试过不同的浏览器吗?你在测试什么webkit?(M.)我只是用纯HTML(删除了angular[(ngModel)]=…
)试了试,效果很好。所以,如果这能缩小你的问题范围的话,很可能与此有关。