1

I have this mat-tab-group :

mat-tab-group
    class="brand-tabs"
    [disableRipple]="true"
    *ngSwitchCase="types.project"
    (selectedTabChange)="changeProjectTab($event)"
    [selectedIndex]="selectedProjectIndex"
>
.........

The function in ts :

changeProjectTab(event) {
    if (event.index > 0) {
        this.selectedProjectIndex = 0;
        this.modalService.contentModal(
            this.upgradeRef,
            this.translateService.instant('message')
        );
    }
}

In this mat-tab-group I have 3 tabs, and I want to stop navigation to tab with index = 1,2, remaining always at tab with index = 0. I tried like this, but not working. Can you give me some ideas please ? Thx

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
frint
  • 771
  • 1
  • 7
  • 14

3 Answers3

1

Just disable the components/tabs that should not be allowed to navigate?

https://material.angular.io/components/tabs/examples - "Basic use of the tab nav bar" - "disabled link"

Ronald Korze
  • 734
  • 5
  • 16
  • I don't want to disable a tab, I just want to remaining in tab 1, and if user click on tab 2 or 3 show a popup – frint Feb 11 '20 at 14:21
1

You need to enable two way binding on selectedIndex:

<mat-tab-group
    ...
    (selectedTabChange)="changeProjectTab($event)"
    [(selectedIndex)]="selectedProjectIndex"
>

Stackblitz example: https://stackblitz.com/edit/angular-lkhtgt.

G. Tranter
  • 16,766
  • 1
  • 48
  • 68
  • is working but if I click on second tab, is displayed the tab 2 and quickly pass to the tab 1, is possible to stop this quick move ? – frint Feb 11 '20 at 14:43
  • Maybe - but it would be tricks to hide/show content - maybe something like `
    Content 1
    `. I updated my stackblitz.
    – G. Tranter Feb 11 '20 at 14:51
0

Did you try adding [disabled]='true' to the mat-tab you want to disable? Maybe you can even add a condition: [disabled]='isFirstTab' or something like that.