如何使用侧边按钮而不是标签页眉来实现 angular material 标签页?

How to implement angular material tabs with side buttons instead of tab header?

这是我的 - Tabs with header

这就是我想要的 - Tabs with side buttons

这是我的代码 -

.html -

<div class="container">
  <button (click)="onPrev()">Prev</button>

  <mat-tab-group [(selectedIndex)]="tabSelect">

    <mat-tab label="First">
      <mat-grid-list cols="3" gutterSize="16px">
        <mat-grid-tile *ngFor="let x of [1,2,3]" class="mat-elevation-z2">
          {{x}}
        </mat-grid-tile>
      </mat-grid-list>
    </mat-tab>

    <mat-tab label="Second">
      <mat-grid-list cols="3" gutterSize="16px">
        <mat-grid-tile *ngFor="let x of [4,5,6]" class="mat-elevation-z2">
          {{x}}
        </mat-grid-tile>
      </mat-grid-list>
    </mat-tab>

  </mat-tab-group>

  <button (click)="onNext()">Next</button>
</div>

.ts -

export class AppComponent {
  tabSelect = 0;
  onPrev() {
    this.tabSelect = 0;
  }
  onNext() {
    this.tabSelect = 1;
  }
}

查询 -

  1. 如何隐藏标签页眉? (当我设置display:none时,tab body也消失了)
  2. 如何在 mat-tab-group 添加侧边按钮? (因为当你正常操作时,按钮不会出现)
  3. 任何其他方式都能给我想要的结果!

我相信正确的答案会帮助很多人。谢谢。

使用 Material 标签制作幻灯片当然是一种奇怪的方式,但是可行。

How do I hide the Tab Header? (when I set display:none, the tab body also disappears)

只需将 display:none 添加到 .mat-tab-label-container - 完全可以。

How do I add side buttons inside mat-tab-group? (because when you do it normally, the buttons don't show up)

你不能,它只是不是为了在里面投影随机内容而设计的,看看模板 https://github.com/angular/components/blob/master/src/material/tabs/tab-group.html 除了选项卡内容之外没有自定义 html 投影 - 只需将按钮留在原处即可。