首页 > 解决方案 > 反应式表单不显示在 html 中

问题描述

我有以下代码。但是表格没有显示出来。有人可以让我知道这段代码有什么问题吗?

 <tfoot>
             <form [formGroup]="profileForm" (ngSubmit)="onSubmit()">
    <tr>
        <td>
            <input class="form-control" type="text" formControlName="type" />
        </td>
        <td>
            <ng-select [items]="parameterType" formControlName="parametertype" [clearable]="false" bindLabel="text" bindValue="id"></ng-select>
        </td>
        <td>
            <ng-select [items]="defaultValues" formControlName="defaultValue" [clearable]="false" bindLabel="text" bindValue="id"></ng-select>
        </td>
        <td>
            <input formControlName="description" class="form-control" type="text" />
        </td>
        <td>
            <button type="submit" [disabled]="!profileForm.valid">
                Submit
            </button>
        </td>
    </tr>

</form>

这是我在组件中的方法。

 ngOnInit() {
                this.profileForm = this._formBuilder.group({
                  'type': ['', [Validators.required, Validators.minLength(5)]],
                  'parametertype': ['', [Validators.required, Validators.minLength(5)]],
                  'defaultValue': ['', [Validators.required, Validators.minLength(5)]],
                  'description': ['', [Validators.required, Validators.minLength(5)]]
                });
              }

标签: angularangular-reactive-forms

解决方案


这对我有用

    <tfoot [formGroup]="profileForm" (ngSubmit)="onSubmit()">

推荐阅读