'mat-toolbar' is not a known element - Angular 5

前端 未结 3 674
太阳男子
太阳男子 2021-01-03 21:14

I have created a new project, and I am trying to add angular-material.

I have created material.module.ts in my app folder:

相关标签:
3条回答
  • 2021-01-03 21:25

    That's because you have to import a module to the module which contains the component declaration, not into the component itself:

    app.module.ts

    import { MaterialModule } from './material.module';
    
    @NgModule({
      imports: [
        // ...
        MaterialModule
      ],
      declarations: [
        MyCoolComponent,
        // ...
      ]
    })
    

    P.S. The correct way to use a material icon is to use the MatIcon component. Example usage:

    <mat-icon>home</mat-icon>
    
    0 讨论(0)
  • 2021-01-03 21:32

    Best way
    for a quick good fix

    import {MatToolbarModule} from '@angular/material/toolbar'; 
    

    in your app.module.ts

    then declare MatToolbarModule in your declarations[].

    0 讨论(0)
  • 2021-01-03 21:50

    Works fine for me here: https://stackblitz.com/edit/angular-w9ckf8

    Look over the link and see if there's anything you are missing.

    0 讨论(0)
提交回复
热议问题