Woo*_*ody 4 html angular-material angular
我已经看到了很多关于此的问题,但似乎不是我遇到的相同问题。我刚刚创建了我的第二个角度项目。我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>
Run Code Online (Sandbox Code Playgroud)
现在,在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 {}
Run Code Online (Sandbox Code Playgroud)
如果mat-card在中使用,也不会有任何错误app.component.html。我在这里想念什么?
我在声明列表中看不到您的EmployeesComponent。需要在与导入MatCardModule的模块相同的模块中声明EmployeesComponent,例如:
declarations: [
EmployeesComponent
],
imports: [
MatCardModule
]
Run Code Online (Sandbox Code Playgroud)
我在猜测是您忘记了在应用程序模块中声明EmployeesComponent,还是在另一个模块(可能是Employees模块)中必须导入MatCardModule。