我已经看到很多关于此的问题,但似乎与我遇到的问题不同。我刚刚创建了我的第二个角度项目。我在 src/app/employees
下有一个新组件,我试图在其中使用 employees.component.html 。我得到的错误是:
Uncaught Error: Template parse errors:
'mat-card' is not a known element:
1. If 'mat-card' is an Angular component, then verify that it is part of this module.
2. If 'mat-card' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message. ("[ERROR ->]<mat-card> </mat-card>
现在,在 app.module.ts 我有:
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations";
import { LOCALE_ID, NgModule } from "@angular/core";
import { HttpClientModule, HTTP_INTERCEPTORS } from "@angular/common/http";
import { AppRoutingModule } from "./app-routing.module";
import { AppComponent } from "./app.component";
import {
MatButtonModule,
MatFormFieldModule,
MatIconModule,
MatInputModule,
MatListModule,
MatSelectModule,
MatSidenavModule,
MatCardModule,
MatTableModule
} from "@angular/material";
@NgModule({
declarations: [AppComponent],
imports: [
BrowserModule,
BrowserAnimationsModule,
AppRoutingModule,
HttpClientModule,
MatButtonModule,
MatFormFieldModule,
MatIconModule,
MatListModule,
MatInputModule,
MatSelectModule,
MatSidenavModule,
MatCardModule,
MatTableModule
],....
})
export class AppModule {}
如果我在 app.component.html
mat-card
则不会出现任何错误。我在这里错过了什么?
原文由 Woody 发布,翻译遵循 CC BY-SA 4.0 许可协议
我在您的声明列表中看不到您的 EmployeesComponent。 EmployeesComponent 需要在导入 MatCardModule 的同一模块中声明,例如:
我猜测要么您忘记在您的应用程序模块中声明 EmployeesComponent,要么您有另一个模块,也许是 Employees 模块,您必须在其中导入 MatCardModule。
您可以将 MatCardModule 导入为