Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Material icon not rendering properly

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>
like image 410
dhana Avatar asked Oct 08 '17 15:10

dhana


People also ask

Where can I find the material icon font?

The material icons are available from the git repository which contains the complete set of icons including all the various formats we are making available. The material icon font is the easiest way to incorporate material icons with web projects.

How to activate the'material icons'font?

Similar to other Google Web Fonts, the correct CSS will be served to activate the 'Material Icons' font specific to the browser. An additional CSS class will be declared called .material-icons .

How to incorporate material icons with web projects?

The material icon font is the easiest way to incorporate material icons with web projects. We have packaged all the material icons into a single font that takes advantage of the typographic rendering capabilities of modern browsers so that web developers can easily incorporate these icons with only a few lines of code.

Why is my icon not working in Angular Material?

If you have overwritten some existing Angular Material styling or any other styling that somehow affects the icon, it may cause an issue. Move the icon code outside of any styling and test. So I just moved it to the child element. Below is part of Angular Material grid.


4 Answers

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';
like image 149
Chris Fremgen Avatar answered Oct 19 '22 02:10

Chris Fremgen


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

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

like image 41
headmelon Avatar answered Oct 19 '22 04:10

headmelon


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;
}
like image 5
jenson-button-event Avatar answered Oct 19 '22 02:10

jenson-button-event


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

@NgModule({
  imports: [
    MatIconModule
  ]
})
like image 2
Dung-Tri LE Avatar answered Oct 19 '22 02:10

Dung-Tri LE