我这样导入MatFormFieldModule
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
//import { MaterialModule } from './material/material.module';
import {MatFormFieldModule} from '@angular/material/form-field';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
AppRoutingModule,
BrowserAnimationsModule,
// MaterialModule,
MatFormFieldModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
我在app.component.html
内(直接取自API文档):
<mat-form-field>
<input matInput placeholder="Input">
</mat-form-field>
ERROR Error: mat-form-field must contain a MatFormFieldControl.
有什么想法吗?
我得到了错误:
ERROR Error: mat-form-field must contain a MatFormFieldControl.
答案 0 :(得分:1)
您还应该导入MatInputModule
:
import {MatInputModule} from '@angular/material/input';
@NgModule({
imports: [
MatFormFieldModule,
MatInputModule,
...
]
})
否则Angular不知道如何为提供<input matInput
的{{1}}初始化指令:
MatFormFieldControl