Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add icon to mat-icon-button

I am using Angular with Material

 <button mat-icon-button><mat-icon svgIcon="thumb-up"></mat-icon>Start Recording</button> 

I am trying to add an icon to button, but I can't figure out how to do it, and can't find documentation for this.

https://material.angular.io/components/button/api

looking the docs, there is this:

enter image description here

that button has the following html:

<a _ngcontent-c1="" aria-label="Angular Material" class="docs-button mat-button" mat-button="" routerlink="/" tabindex="0" aria-disabled="false" href="/"><span class="mat-button-wrapper">     <img _ngcontent-c1="" alt="angular" class="docs-angular-logo" src="../../../assets/img/homepage/angular-white-transparent.svg">     <span _ngcontent-c1="">Material</span>   </span> <div class="mat-button-ripple mat-ripple" matripple=""></div><div class="mat-button-focus-overlay"> </div> </a> 

is that the right way to do it?

like image 795
Alexander Mills Avatar asked Jan 05 '18 03:01

Alexander Mills


People also ask

What is material icons in Angular?

Angular Material Icons are a set of prebuilt icons that can be easily imported into the app. Except for the bitmap-based formats ie., png, jpg, etc, this directive can support both icon fonts and SVG icons. Syntax: <mat-icon> Icon Name </mat-icon>

How do I use material icons in Angular 12?

To use Material icons in Angular, use <mat-icon> component. The <mat-icon> directive supports both icon fonts and SVG icons, but not bitmap-based formats. Icons are the necessary components when building modern-day web apps, and sometimes they can be frustrating.


1 Answers

Just add the <mat-icon> inside mat-button or mat-raised-button. See the example below. Note that I am using material icon instead of your svg for demo purpose:

<button mat-button>     <mat-icon>mic</mat-icon>     Start Recording </button> 

OR

<button mat-raised-button color="accent">     <mat-icon>mic</mat-icon>     Start Recording </button> 

Here is a link to stackblitz demo.

like image 75
Faisal Avatar answered Sep 25 '22 06:09

Faisal