使用反应性FormGroup或FormControlName设置angular6选择选项的值

时间:2019-03-01 07:09:15

标签: angular6 angular-material-6

我试图在reactform方法的帮助下通过setValue()来为angular6 select(Drop down)设置值,但是只有输入值是我分配的,但没有分配给下拉菜单,我需要帮助。

<div [formGroup]="empOrInstuteFormData">
<mat-form-field fxFlex="100%" appearance="fill">
        <mat-label>Select Client</mat-label>
        <mat-select formControlName="empclientname">
          <mat-option *ngFor="let empclient of empclients" [value]="empclient.id">{{empclient.name}}</mat-option>
        </mat-select>
      </mat-form-field>
</div>

 editCellData(tabelinfo) {
    this.empOrInstuteFormData.setValue({
      type: '',
      empnamesearch: '',
      employername: tabelinfo.employername,
      institutenamesearch: '',
      empclientname: tabelinfo.clientname,
      empaddress: tabelinfo.address,
      instituteName: '',
      institutecategory: '',
      instituteclient: '',
      institutedate: '',
      instituteaddorlocation: '',
      institutesource: '',
      instituteresearchorremark: '',
      instituecomments: ''
    })
  }

在单击表编辑图标时,此editcellData()方法将调用并显示相应的输入字段。但是下拉列表中没有选择值。

0 个答案:

没有答案