Skip to main content

angular material - How to use FAB

app.component.ts

import { Component } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})


export class AppComponent {
  counter: number = 0;

  updateCounter(){
    this.counter++;
  }
}
app.component.html

<h2>Angular Material - How to use FAB</h2>

<h1>{{counter}}</h1>


<div style="display:flex; justify-content:space-between;
      padding:20px;">
  <button mat-fab (click)="updateCounter()"
    aria-label="Basic material fab">
      <mat-icon>cancel</mat-icon>
  </button>
  
  <button mat-fab color="primary" (click)="updateCounter()"
    aria-label="Primary color fab">
      <mat-icon>delete</mat-icon>
  </button>
  
  <button mat-fab color="accent" (click)="updateCounter()"
    aria-label="Accent color fab">
      <mat-icon>grade</mat-icon>
  </button>
  
  <button mat-fab color="warn" (click)="updateCounter()"
    aria-label="Warn color fab">
      <mat-icon>download</mat-icon>
  </button>
</div>


<div style="display:flex; justify-content:space-between;
      padding:20px; background-color:gray;">
  <button mat-fab disabled (click)="updateCounter()"
    aria-label="Disabled fab">
      <mat-icon>zoom_in</mat-icon>
  </button>
</div>
app.module.ts [import]

// for material button
import {MatButtonModule} from '@angular/material/button';

// for material icon
import {MatIconModule} from '@angular/material/icon';
More Angular tutorials