gpt4 book ai didi

css - 在 Angular Material 的垂直选项卡列表中添加选项卡按钮

转载 作者:太空宇宙 更新时间:2023-11-04 05:42:34 25 4
gpt4 key购买 nike

我已经使用 Angular Material 创建了垂直选项卡,并想添加 Add Tab 按钮,我可以添加该按钮,但它是在底部添加的。我想在垂直标签列表中添加该按钮。

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

html:

<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:

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按钮垂直标签?

最佳答案

<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 之前或之后使用它

关于css - 在 Angular Material 的垂直选项卡列表中添加选项卡按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59044155/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com