使用角度6的动态制表符

问题描述 投票:1回答:1

我将tabset用于标签。

例如:https://stackblitz.com/edit/ngx-bootstrap-tabs-manual?file=app%2Fapp.module.ts

我需要使用ngx-bootstrap,tabset关闭并动态添加选项卡。

有人可以帮我提供动态标签吗?

typescript angular6 angular5 angular7
1个回答
1
投票

请在下面的[[app.component.html HTML文件中替换以下HTML代码以获取动态标签]

<alert type="success"> <strong>Tabs!</strong> you can enable/disable tab switching with the button here. </alert> <label for="switcher">Disable tab switching: <input type="checkbox" [(ngModel)]="disableSwitching"></label> <p>Tab switching is <strong>{{ disableSwitching ? 'disabled' : 'enabled ' }}</strong>.</p> <hr> <tabset #tabset> <tab *ngFor="let tab of tabsetData" [heading]="tab.tabtitle" [innerHTML]="tab.tabContent"></tab> </tabset> <button (click)='goto(0)'>Go to 1</button> <button (click)='goto(1)'>Go to 2</button> <button (click)='goto(2)'>Go to 3</button>
对于

app.component.ts

文件代码import { Component, ViewChild , ViewChildren , QueryList , AfterViewInit } from '@angular/core'; import { TabsetComponent, TabDirective } from 'ngx-bootstrap/tabs'; @Component({ selector: 'my-app', templateUrl: './app.component.html', styleUrls: [ './app.component.css' ] }) export class AppComponent implements AfterViewInit { disableSwitching: boolean; @ViewChild('tabset') tabset: TabsetComponent; tabsetData = [{ tabtitle: "First Tab", tabContent: "<p>First Tab</p>" },{ tabtitle: "Second Tab", tabContent: "<p>Second Tab</p>" },{ tabtitle: "Third Tab", tabContent: "<p>Third Tab</p>" }]; ngAfterViewInit(){ console.log(this.tabset.tabs); } goto(id){ this.tabset.tabs[id].active = true; } }
希望这会有所帮助!谢谢。
© www.soinside.com 2019 - 2024. All rights reserved.