[英]Input field not updated in Reactive Forms Angular 4
I'm using reactive forms in an Angular application. 我在Angular应用程序中使用反应形式。 I have 2 fields, one is a select (named client) and the other one an input (named clientCode) which has to be updated the user selects a new client. 我有2个字段,一个字段是一个select(命名为client),另一个字段是一个输入(命名为clientCode),用户必须对其进行更新,以便用户选择一个新的客户端。
<select formControlName="client">
<option value="">Client</option>
<option *ngFor="let item of data.clients" [value]="item.value">{{ item.value }}</option>
</select>
<input type="text" formControlName="clientCode" placeholder="Client Code" value="{{ clientCode$ | async }}">
I'm using valueChanges over client, so that when the user selects a client I get the code associated to that client and it returns it as an Observable (clientCode$) which then updates the input value. 我在客户端上使用valueChanges,以便当用户选择一个客户端时,我获得与该客户端关联的代码,并将其作为Observable(clientCode $)返回,然后更新输入值。
this.clientCode$ = this.summary
.get('client')
.valueChanges.map(val => this.clientsMap.get(val));
This is working in my screen, as the clientCode is displayed, but the form itself is not updated. 这在我的屏幕上有效,因为显示了clientCode,但是表单本身未更新。 Only when I click in the input field and type something is updated. 仅当我单击输入字段并键入内容时,才会更新。
Is there any way to fix this? 有没有什么办法解决这一问题?
Thanks 谢谢
In order to update control model successfully you can use ngModel
property instead of value
. 为了成功更新控件模型,可以使用ngModel
属性而不是value
。
It might look like: 它可能看起来像:
[ngModel]="clientCode$ | async"
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.