Angular 8表单组可以绑定到下拉选项吗?

时间:2019-09-26 14:26:01

标签: angular angular-material formgroups

我有一个如下所示的嵌套表单组

  studentForm = this.formBuilder.group({
    Score: ['', Validators.compose([Validators.required, Validators.max(100), Validators.min(0)])],
    license: this.formBuilder.group({
       chineseName: ['', Validators.compose([Validators.required, Validators.maxLength(100)])],
       englishName: ['', Validators.compose([Validators.required, Validators.maxLength(100)])],
    });
  });

studentForm包含一个分数和许可证,一个学生有一个许可证

我将许可证表格组绑定到如下所示的有角材料上

 <form [formGroup]="studentForm ">
        <mat-form-field>
          <mat-label>license</mat-label>
          <mat-select formControlName="license">
            <mat-option *ngFor="let option of licenses" [value]="option">
              {{option.chineseName}},{{option.englishName}}
            </mat-option>
          </mat-select>
        </mat-form-field>
</form>

但我会收到此错误

StudentComponent.html:9 ERROR TypeError: control.registerOnChange is not a function
    at setUpModelChangePipeline (forms.js:2701)
    at setUpControl (forms.js:2580)
    at FormGroupDirective.addControl (forms.js:6318)
    at FormControlName._setUpControl (forms.js:6969)
    at FormControlName.ngOnChanges (forms.js:6892)
    at checkAndUpdateDirectiveInline (core.js:24499)
    at checkAndUpdateNodeInline (core.js:35163)
    at checkAndUpdateNode (core.js:35102)
    at debugCheckAndUpdateNode (core.js:36124)
    at debugCheckDirectivesFn (core.js:36067)

是否可以将表单组绑定到下拉列表?

谢谢大家

0 个答案:

没有答案