简体   繁体   English

输入字段未在Reactive Forms Angular 4中更新

[英]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"

Plunker Example 柱塞示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从 Reactive Forms Angular 的输入字段获取更新的值 - Getting Updated Value from Input Field from Reactive Forms Angular Angular 反应性 Forms 输入错误(输入字段未显示) - Angular Reactive Forms Input Error (input field not showing) Angular =&gt; 反应式 Forms:在遇到空输入字段时禁用按钮 - Angular => Reactive Forms : disable button when it encounters an empty input field 如何以角度反应形式修补或设置特定输入字段的值 - How to patch or set value for particular input field in angular reactive forms angular 反应式 forms - 无效输入的样式字段颜色 - angular reactive forms - styling field color on invalid input angular 无功 forms 禁用场 - angular reactive forms disable field angular 的输入事件和反应 forms - Input event and reactive forms of angular fromcontrol 值未使用离子 5 / angular 中的反应性 forms 更新 - fromcontrol value is not updated with reactive forms in ionic 5 / angular Angular2 Reactive表单 - 设置表单输入字段的默认值(输入类型=文件)? - Angular2 Reactive forms - Set default value for form input field (input type=file)? angular 7 反应式 forms:为表单中的每个输入字段动态添加/删除输入字段 - angular 7 reactive forms: dynamically add / remove input fields for each input field in the form
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM