【问题标题】:How will I get the active tab name in ngb-tabset on load of the component in angular? [closed]如何在 ngb-tabset 中以角度加载组件时获取活动选项卡名称? [关闭]
【发布时间】:2020-05-18 23:30:47
【问题描述】:

我在我的项目中使用了 ngbTabset 作为选项卡。但是当应用程序加载时,我无法在控制台中获取活动选项卡名称。请提出任何解决方案。

【问题讨论】:

标签: html angularjs angular bootstrap-4 angular-material


【解决方案1】:

它只是询问 activeId - 如果您的 ngb-tab 有 id,则返回这个值,否则返回一个“随机”名称 -。获取ngbTab可以使用ViewChild,也可以查看API of ngb-tabset获取其他属性或方法

stackblitz

  @ViewChild(NgbTabset,{static:false}) tabset
  ngAfterViewInit()
  {
    console.log(this.tabset.activeId)
  }

【讨论】:

    【解决方案2】:
    HTML:
    <div class="col-md-12">
      <ngb-tabset #t="ngbTabset" *ngIf="tabData" type="groups">
        <ngb-tab *ngFor="let tab of tabData.groups" title={{tab.name}} >
            <div></div>
        </ngb-tab>
      </ngb-tabset>
    </div>
    
    
    TS:  
    
    
           export class MyTabs implements OnInit {   
    
              private tabSet: ViewContainerRef;    
    
              @ViewChild(NgbTabset) set content(content: ViewContainerRef) { 
    
                this.tabSet = content;  
    
              };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-10-14
      • 1970-01-01
      • 2018-05-29
      • 1970-01-01
      • 1970-01-01
      • 2022-08-05
      • 1970-01-01
      相关资源
      最近更新 更多