简体   繁体   中英

Error using mat-icon of angular material with Angular 10

I have a MaterialModule

import { NgModule } from '@angular/core';
import {MatButtonModule} from '@angular/material/button';
import {MatIconModule} from '@angular/material/icon';

@NgModule({
 declarations: [],
 imports: [
  MatButtonModule,
  MatIconModule
 ]
})
export class MaterialModule { }

And I import this module in my App Module

应用模块

Then in app.component.html I try to use the mat-icon component

<button mat-button>
<mat-icon>face</mat-icon>
Click me!
</button>

but always get this error

错误

Any idea please?

Thanks

You have to export both MatButtonModule and MatIconModule in your MaterialModule

import { NgModule } from '@angular/core';
import {MatButtonModule} from '@angular/material/button';
import {MatIconModule} from '@angular/material/icon';

@NgModule({
 declarations: [],
 imports: [
   MatButtonModule,
   MatIconModule
 ],
 exports: [
   MatButtonModule,
   MatIconModule
 ]
 })
 export class MaterialModule { }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM