formGroup需要一个formGroup实例.请传入一个.如何修复此错误



我的HTML源代码如下,

<p>
<mat-form-field appearance="legacy" [formGroup]="form" (submit)="onFormSubmit()">
<mat-label>Add a List</mat-label>
<input [(ngModel)]="listName" matInput placeholder="Placeholder" formControlName="name" #nameInput fxFlex>
<mat-icon matSuffix class="check" (click)="onFormSubmit()">check</mat-icon>
<mat-icon matSuffix class="clear" (click)="closeForm()">clear</mat-icon>
</mat-form-field>
</p>

当运行此代码时,控制台上显示以下错误,

ERROR Error: formGroup expects a FormGroup instance. Please pass one in.
Example:

<div [formGroup]="myGroup">
<input formControlName="firstName">
</div>
In your class:
this.myGroup = new FormGroup({
firstName: new FormControl()
});

如何修复此错误?

打字?您写道:

[formGroup]="form"

应该是:

[formGroup]="myGroup"

相关内容

  • 没有找到相关文章

最新更新