请记住,在角5选择的标签(引导标签集)

问题描述 投票:0回答:2

我在一个角5应用程序中使用的自举(NGX-bootstrap.es2015.js)标签集。它工作正常的大部分。然而,当显示另一个组件(和显示的标签集组件是隐藏的),然后你回去显示标签集的组成部分,标签集始终显示为选择(尽管可能是第三一个被选中)第一个标签。有没有一种方法来“记住”回归“第一”组件时,这片活跃?

一些代码:

<tabset type="pills" [justified]="true" *ngIf="someCondition ">
      <tab *ngFor="let category of categories"
           heading="{{category.categoryNumber}} {{category.categoryName}}"
           (select)=setCategory(category.categoryNumber)>
      </tab>
    </tabset>

setCategory(categoryNumber) {
    this.currentCategory = categoryNumber;
    this._ref.detectChanges();
    ...
  }
angular twitter-bootstrap-3 ngx-bootstrap
2个回答
0
投票

你必须把一些状态到您的应用程序,以便它记住某些数据块。我用this链接过去更多地了解我的角度应用内创建这样一个状态。


0
投票

在这种情况下,我通常使用某种类型的标志,平时对我注射服务,这使选择的选项。然后,我设置使用ngClass基于对服务价值的“积极”级。因此,沿着这个线的东西:

<tabset type="pills" [justified]="true" *ngIf="someCondition ">
  <tab *ngFor="let category of categories"
       heading="{{category.categoryNumber}} {{category.categoryName}}"
       [ngClass]="{ 'active' : category.categoryNumber === someSvc.selectedCategoryNumber }"
       (select)=setCategory(category.categoryNumber)>
  </tab>
</tabset>

constructor(private someSvc: MySomeService) { }

setCategory(categoryNumber) {
    this.someSvc.selectedCategoryNumber = categoryNumber;
    this.currentCategory = categoryNumber;
    this._ref.detectChanges();
    ...
}

我敢肯定有一个更优雅的方式,希望有人来一起显示,我们俩的,但它总是工作的很好,我,因为我几乎总是注入某种服务的几乎每一个部件。

© www.soinside.com 2019 - 2024. All rights reserved.