我的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"