- Make sure you have link to icon in index.html
- All the icons are present at : https://material.io/resources/icons/?style=baseline
index.html
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
material.module.ts (a new module added)
import { NgModule } from '@angular/core'; import { MatButtonModule } from '@angular/material'; import { MatButtonToggleModule} from '@angular/material/button-toggle'; import { MatIconModule} from '@angular/material/icon'; const MaterialComponent = [ MatButtonModule, MatButtonToggleModule, MatIconModule ]; @NgModule({ imports: [ MaterialComponent, ], exports: [ MaterialComponent ] }) export class MaterialModule { }
app.module.ts
import { BrowserModule } from '@angular/platform-browser'; import { NgModule } from '@angular/core'; import { AppComponent } from './app.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { MaterialModule } from './material/material.module'; @NgModule({ declarations: [ AppComponent ], imports: [ BrowserModule, BrowserAnimationsModule, MaterialModule ], providers: [], bootstrap: [AppComponent] }) export class AppModule { }
app.component.html
<div><mat-icon color="primary">description</mat-icon></div> <div><mat-icon color="accent">card_giftcard</mat-icon></div> <div><mat-icon color="warn">commute</mat-icon></div>
Output :