【问题标题】:Dynamic tabs using angular 6使用 Angular 6 的动态选项卡
【发布时间】:2020-02-15 13:07:37
【问题描述】:

我将 tabset 用于标签。

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

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

谁能帮我做动态标签。

【问题讨论】:

    标签: typescript angular6 angular5 angular7


    【解决方案1】:

    请将app.component.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;
      }
    }
    

    希望这会有所帮助!谢谢。

    【讨论】:

      猜你喜欢
      • 2019-01-03
      • 1970-01-01
      • 1970-01-01
      • 2018-12-16
      • 2016-10-25
      • 1970-01-01
      • 2014-07-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多