模块 '"@angular/material"' 没有导出成员 'MatFormFieldModule'

Module '"@angular/material"' has no exported member 'MatFormFieldModule'

我将在 Angular 12.

中使用 MatFormFieldModule

我从 @angular/material@NgModule 导入了这个模块,如下所示:

import {MatFormFieldModule} from '@angular/material';


@NgModule({
....

imports: [
  MatFormFieldModule,
  ...
  ],
...

})

并在 html 文件中使用了这个 MatFormFieldModule

<mat-form-field>
  ...
</mat-form-field>

但是我得到了这样的错误:

Error: src/app/app.module.ts:9:3 - error TS2305: Module '"@angular/material"' has no exported member 'MatFormFieldModule'.

9   MatFormFieldModule

不确定这个问题。

如果您检查 the documentation for the material form field,您会注意到 MatFormFieldModule 的正确导入路径是 @angular/material/form-field。请试试这个:

import {MatFormFieldModule} from '@angular/material/form-field';