If you want fully dynamic then create an array of button names.
buttons = ['Button 1', 'Button 2', 'Button 3'];
And a variable for the selected button and assign the first button as selected.
selectedButton: string = this.buttons[0];
Create a function to check the selected button.
isButtonSelected(button: string) {
return button === this.selectedButton;
}
Add switchButton function to toggle your selection.
switchButton(button: string) {
this.selectedButton = button;
}
Iterate your buttons at HTML:
<ng-container *ngFor="let button of buttons">
<button mat-button [ngClass]="{'mat-raised-button':isButtonSelected(button)}" (click)="switchButton(button)">{{button}}</button>
</ng-container>
You can now change mat-raised-button to any other button type as your wish.
See detail in working demo at StackBlitz.
:activepseudo class. See here.