Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return in the last tabs in javascript (Angular Material) with a button?

My code summary

I want if I click on "go back content", I return at the content tabs 1;

<mat-tab-group mat-stretch-tabs>
    <mat-tab label="content 1">
        ........
    </mat-tab>
    <mat-tab label="content 2">
        <button mat-raised-button (click)=""> go Back content 1</button>
    </mat-tab>
</mat-tab-group>
like image 725
Bruno Marcelino Avatar asked Apr 29 '26 06:04

Bruno Marcelino


1 Answers

You can bind the current selected tab's index to a variable and then set that variable when needed, like this:

<mat-tab-group mat-stretch-tabs [selectedIndex]="selectedIndex">
    <mat-tab label="content 1">
        ........
    </mat-tab>
    <mat-tab label="content 2">
        <button mat-raised-button (click)="selectedIndex = 0"> go Back content 1</button>
    </mat-tab>
</mat-tab-group>

You can read more here.

like image 134
Shai Avatar answered Apr 30 '26 21:04

Shai



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!