Angular mat-form-field 未找到 "ngForm"
Angular mat-form-filed not finding "ngForm"
在我的 Angular 应用程序中:我想从这个工作良好的表单切换:
<form autocomplete="off" #searchActor="ngForm"
(ngSubmit)= submitForm(searchActor.value)
class="ml-2 mr-2 my-auto">
<input type="text" name="actorSearch"
(ngModel)="model.searchActor">
</form>
给这个angular material一个:
<mat-form-field #searchActor="ngForm"
(ngSubmit)= submitForm(searchActor.value)
class="ml-2 mr-2 my-auto">
<mat-label>Custom Search</mat-label>
<input matInput type="text"
name="actorSearch"
placeholder="Ex. young, cartoon..."
(ngModel)="model.searchActor">
<button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
这是我的进口商品:
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
BrowserAnimationsModule,
MatSliderModule,
MatSlideToggleModule,
MatSelectModule,
MatButtonModule,
MatIconModule,
MatInputModule,
MatFormFieldModule,
],
但是每当我加载我的应用程序时,我都会收到此错误:
知道如何解决这个问题吗?
你应该留下表格标签
<form autocomplete="off" #searchActor="ngForm" (ngSubmit)= submitForm(searchActor.value) class="ml-2 mr-2 my-auto">
并描述里面的每个字段
语法错误
像这样
<form novalidate #searchActor ="ngForm">
<mat-form-field class="example-full-width">
<input matInput placeholder="Favorite food" name="myname" required [(ngModel)]="comment">
<mat-error>Is required lol</mat-error>
</mat-form-field>
</form>
在我的 Angular 应用程序中:我想从这个工作良好的表单切换:
<form autocomplete="off" #searchActor="ngForm"
(ngSubmit)= submitForm(searchActor.value)
class="ml-2 mr-2 my-auto">
<input type="text" name="actorSearch"
(ngModel)="model.searchActor">
</form>
给这个angular material一个:
<mat-form-field #searchActor="ngForm"
(ngSubmit)= submitForm(searchActor.value)
class="ml-2 mr-2 my-auto">
<mat-label>Custom Search</mat-label>
<input matInput type="text"
name="actorSearch"
placeholder="Ex. young, cartoon..."
(ngModel)="model.searchActor">
<button mat-button *ngIf="value" matSuffix mat-icon-button aria-label="Clear" (click)="value=''">
<mat-icon>close</mat-icon>
</button>
</mat-form-field>
这是我的进口商品:
imports: [
BrowserModule,
AppRoutingModule,
HttpClientModule,
FormsModule,
BrowserAnimationsModule,
MatSliderModule,
MatSlideToggleModule,
MatSelectModule,
MatButtonModule,
MatIconModule,
MatInputModule,
MatFormFieldModule,
],
但是每当我加载我的应用程序时,我都会收到此错误:
知道如何解决这个问题吗?
你应该留下表格标签
<form autocomplete="off" #searchActor="ngForm" (ngSubmit)= submitForm(searchActor.value) class="ml-2 mr-2 my-auto">
并描述里面的每个字段
语法错误 像这样
<form novalidate #searchActor ="ngForm">
<mat-form-field class="example-full-width">
<input matInput placeholder="Favorite food" name="myname" required [(ngModel)]="comment">
<mat-error>Is required lol</mat-error>
</mat-form-field>
</form>