app.component.ts
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
isBadgeHidden:boolean = false;
toggleBadgeVisibility(){
this.isBadgeHidden = !this.isBadgeHidden;
}
}
app.component.html
<h2 style="padding-top:25px; padding-bottom:25px;">
Angular Material - How to toggle Badge visibility
</h2>
<h3>Toggle badge visibility on button click</h3>
<button
mat-raised-button matBadge="6"
[matBadgeHidden]="isBadgeHidden"
(click)="toggleBadgeVisibility()">
{{isBadgeHidden? 'Show Badge' : 'Hide Badge'}}
</button>
app.module.ts [import]
import { MatBadgeModule } from '@angular/material/badge'
import { MatButtonModule } from '@angular/material/button'
- angular material - How to change Badge position
- angular material - How to show Badge in a button
- angular material - How to show Badge with icon
- angular material - Badge position before & below after
- angular material - Open Accordion multiple panels at once
- angular material - How to disable a panel in Accordion
- angular material - How to hide Accordion panels toggle icon
- angular material - Icon inside Expansion Panel header
- angular material - Show Accordion toggle icon on left
- angular material - Open & close Accordion all panels at once
- angular material - Determine an Expansion Panel is opened or closed
- angular material - Determine an Expansion Panel is disabled or enabled
- angular material - How to toggle Expansion Panel expanded state
- angular material - Expansion Panel expandedChange event
- angular material - How to change Expansion Panel header height