ole*_*ank 3 angular-material angular
我收到错误消息ERROR mat-form-field must contain a MatFormFieldControl,这应该意味着我需要在最近的父模块中导入MatFormFieldModule。但是我已经做了,所以我不明白问题出在什么地方...
模板
<form [formGroup]="form" (ngSubmit)="handleSubmit()">
<mat-form-field>
<input matInput placeholder="Name" formControlName="name" />
</mat-form-field>
<mat-form-field>
<textarea
matInput
placeholder="Active Description"
formControlName="activeDescription"
></textarea>
</mat-form-field>
<mat-form-field>
<textarea
matInput
placeholder="Inactive Description"
formControlName="inactiveDescription"
></textarea>
</mat-form-field>
<mat-form-field>
<mat-checkbox formControlName="active">Active</mat-checkbox>
</mat-form-field>
</form>
Run Code Online (Sandbox Code Playgroud)
模组
import { CommonModule } from '@angular/common';
import { NgModule } from '@angular/core';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule, MatCheckboxModule, MatFormFieldModule, MatInputModule, MatSelectModule } from '@angular/material';
import { EffectsModule } from '@ngrx/effects';
import { StoreModule } from '@ngrx/store';
import { PaymentConfigSelectorComponent } from './payment-config-selector/payment-config-selector.component';
import { PaymentMethodComponent } from './payment-method/payment-method.component';
import { PaymentMethodsComponent } from './payment-methods/payment-methods.component';
import { PaymentRoutingModule } from './payment-routing.module';
import { PaymentEffects } from './payment.effects';
import { paymentReducer } from './payment.reducer';
import { PaymentSmartComponent } from './smart/payment-smart.component';
@NgModule({
declarations: [PaymentSmartComponent, PaymentMethodsComponent, PaymentConfigSelectorComponent, PaymentMethodComponent ],
imports: [
CommonModule,
PaymentRoutingModule,
FormsModule,
ReactiveFormsModule,
EffectsModule.forFeature([PaymentEffects]),
StoreModule.forFeature(
'payment',
paymentReducer,
),
MatFormFieldModule, MatInputModule, MatSelectModule, MatCheckboxModule, MatButtonModule,
],
providers: [
],
})
export class PaymentModule { }
Run Code Online (Sandbox Code Playgroud)
Raw*_*ode 16
我必须这样做才能让它发挥作用:-
<mat-form-field>
<input hidden=true matInput> // this gets rid of the error, while the form still uses the input received in the
mat-checkbox
<mat-checkbox matInput formControlName="active">Active</mat-checkbox>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
小智 12
我通过添加隐藏的输入字段解决了该问题。
<mat-form-field>
<mat-label>My Label</mat-label>
<input matInput [hidden]="true" [(ngModel)]="myModel" name="myModel">
<mat-checkbox class="ml-3" [(ngModel)]="myModel" name="myModel"></mat-checkbox>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
实际上,该错误并不意味着模块导入问题,而是您在使用mat-form-field没有有效控件的情况。
问题在这里:
<mat-form-field>
<mat-checkbox formControlName="active">Active</mat-checkbox>
</mat-form-field>
Run Code Online (Sandbox Code Playgroud)
MatChebox不应包含在中mat-form-field。Juste取出容器
| 归档时间: |
|
| 查看次数: |
1941 次 |
| 最近记录: |