25

Material icon not rendering properly in my project, i installed properly but even though not showing in browser.

i followed below steps:

npm install material-design-icons

.angular-cli.json

"styles": [
        "styles.css",
        "../node_modules/material-design-icons/iconfont/material-icons.css"
      ],

app.module.ts

import {MatSidenavModule, MatToolbarModule, MatIconModule} from '@angular/material';

app.component.html

<mat-toolbar-row>
    <span>Second Line</span>
    <span class="example-spacer"></span>
    <mat-icon class="example-icon">verified_user</mat-icon>
  </mat-toolbar-row>
Edric
  • 24,639
  • 13
  • 81
  • 91
dhana
  • 857
  • 3
  • 11
  • 26
  • `mat-icon` -> `md-icon`, prior to the release yesterday it was the preferred route to import `MdIconModule` rather than `MatIconModule` as well. – Z. Bagley Oct 08 '17 at 16:21
  • 1
    Side note... did you make sure to include the actual fonts (and not just the css) http://google.github.io/material-design-icons/#icon-font-for-the-web? – Z. Bagley Oct 08 '17 at 16:24

8 Answers8

29

I had the same issue. Caused because I was importing the material theme before the fonts in my theme.scss.

Should be:

@import url( 'https://fonts.googleapis.com/css?family=Roboto:400,700|Material+Icons');

@import '~@angular/material/theming';
Chris Fremgen
  • 4,649
  • 1
  • 26
  • 26
7

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

make sure this has been added to your index.html.

headmelon
  • 83
  • 1
  • 6
5

I had made my own text font !important

had to make the icons more important:

.lato * {
  font-family: 'Lato' !important;
}

.mat-icon{
  font-family: 'Material Icons' !important;
}
jenson-button-event
  • 18,101
  • 11
  • 89
  • 155
2

I had the same issue, because I forgot to add the module on NgModule.imports :

@NgModule({
  imports: [
    MatIconModule
  ]
})
1

consider using google CDN instead by adding the following to your index.html:

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

Edit:

move/download the CSS file and place it in your assets folder and then in your angular-cli.json you add the following to your styles array:

"../src/assets/material-icons.css"
Hamed Baatour
  • 6,664
  • 3
  • 35
  • 47
0

Ran into this in Angular 6, solution ended up being adding mat-icon-button,

<button mat-icon-button type="button" 
    (click)="yourMethod()">
    <mat-icon>delete</mat-icon>
</button>

Make sure you add MatIconModule to your app.module.ts imports and it should work like a charm.

GoranSu
  • 479
  • 4
  • 9
0

Check your console for miscellaneous errors.

If you have a miscellaneous error in your component it could be preventing your mat-icon from initializing properly and you'll just see the textual representation of the glyph instead.

Simon_Weaver
  • 140,023
  • 84
  • 646
  • 689
0

I faced same issue, instead of icon "close" text was coming for me. It was internet issue , internet was slow so maticon module was not loaded properly. Reconnecting with good network strength solved my issue.

harsh
  • 1