小编Hom*_*one的帖子

Angular mat-form-filed 找不到“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>
Run Code Online (Sandbox Code Playgroud)

对于这种有棱角的材料:

    <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>
Run Code Online (Sandbox Code Playgroud)

这是我的进口:

imports: [
    BrowserModule,
    AppRoutingModule,
    HttpClientModule,
    FormsModule,
    BrowserAnimationsModule,
    MatSliderModule,
    MatSlideToggleModule,
    MatSelectModule,
    MatButtonModule,
    MatIconModule,
    MatInputModule,
    MatFormFieldModule,
  ],  
Run Code Online (Sandbox Code Playgroud)

但是每当我加载我的应用程序时,我都会收到此错误:

错误日志

知道我该如何解决这个问题吗?

angular-material angular angular-forms

1
推荐指数
1
解决办法
69
查看次数

标签 统计

angular ×1

angular-forms ×1

angular-material ×1