首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在垂直制表符列表中添加选项卡按钮(角材料)

问在垂直制表符列表中添加选项卡按钮(角材料)
EN

Stack Overflow用户
提问于 2019-11-26 05:12:37
回答 2查看 2.5K关注 0票数 1

我已经创建了垂直选项卡使用角材料,并希望添加Add Tab按钮,我可以添加该按钮,但它添加在底部。我想在垂直标签列表中添加这个按钮。

这里是stackblitz链接,它在单击按钮时添加选项卡。Add Tab按钮应该在垂直选项卡中。

html:

代码语言:javascript
复制
<mat-tab-group [selectedIndex]="selected.value" (selectedIndexChange)="selected.setValue($event)">
  <mat-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
    Contents for {{tab}} tab
  </mat-tab>
</mat-tab-group>
<button mat-raised-button class="example-add-tab-button add-tab-btn" (click)="addTab()">  Add Tab </button>

TS:

代码语言:javascript
复制
import {Component} from '@angular/core';
import { FormControl} from '@angular/forms';

/**
 * @title Basic use of the tab group
 */
@Component({
  selector: 'tab-group-basic-example',
  templateUrl: 'tab-group-basic-example.html',
  styleUrls: ['tab-group-basic-example.css'],
})
export class TabGroupBasicExample {
  tabs = ['First', 'Second'];
  selected = new FormControl(0);
  selectAfterAdding: boolean;
  addTab() {
    this.selectAfterAdding = true;
    this.tabs.push('New');
    if(this.selectAfterAdding) {
      this.selected.setValue(this.tabs.length - 1);
    }
  }
}

如何添加Add Tab按钮垂直选项卡?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-11-26 05:21:39

代码语言:javascript
复制
<mat-tab-group [selectedIndex]="selected.value" (selectedIndexChange)="selected.setValue($event)">

<mat-tab disabled>
                <ng-template mat-tab-label>
                    <button mat-icon-button (click)="addTab()">
                        <mat-icon>add_circle</mat-icon>
                    </button>
                </ng-template>
          </mat-tab>

  <mat-tab *ngFor="let tab of tabs; let index = index" [label]="tab">
    Contents for {{tab}} tab
  </mat-tab>
</mat-tab-group> 

在您的ng-for之前或之后使用这个

票数 3
EN

Stack Overflow用户

发布于 2019-11-26 05:44:49

你的灵活方向是“列”。您需要将此“列”更改为“行”;

代码语言:javascript
复制
 .mat-tab-labels{ 
     flex-direction:row !important;
 }
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59044155

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档