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:
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?
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>
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With