Angular2 Poller重置ng-bootstrap accordin

时间:2017-04-07 20:35:03

标签: angular rxjs ng-bootstrap

我有一个多维数组连接到等待数据库状态更新的反应式轮询器。如果我加载状态1x ui按预期工作。

问题:当我打开轮询器时,会导致手风琴状态关闭。

代码:

<ngb-accordion #acc="ngbAccordion" [closeOthers]="true">
    <ngb-panel *ngFor="let group of fishGroups | async" title="{{group[0].source.originalname}}">
        <template ngbPanelContent>
            ......
        </template>
    </ngb-panel>
</ngb-accordion>


ngOnInit() {
  console.log('ngOnInit');

  this.fishGroups = this.fisheService.elements
    //ensure not null
    .filter((arr: DTOfish[]) => (arr != null && arr.length > 0))
    // create milti dimensional array

    .map((fishes : DTOfish[]) => {
      let groups: DTOfish[][] = [];
      fishes.forEach((fish: DTOfish) => {
        //note double assignment : if null create
        let group: DTOfish[] = groups[fish.source.id] = groups[fish.source.id] ? groups[fish.source.id] : [];
        group.push(fish);
      });

      //make sparse array dense
      return groups.filter(value => !!value);
    });

  this.fishes = this.fisheService.elements.map((fishes: DTOfish[]) => {
    return fishes.filter((fish: DTOfish) => !fish.model.isFailed)
  });


  this.fisheService.loadAll();

  this._interval = global.setInterval( () => {
    console.log('fishComponent Poller');
    this.fisheService.loadAll();
  }, 2000);

}

问题: 当轮询器返回更新状态时,如何保持选定的内容面板处于打开状态?

1 个答案:

答案 0 :(得分:0)

该组件采用活动元素ID的值OR数组。当数据发生变化时,变量中的所有值都将保持打开状态。

@Input() activeIds: string | string[] = [];

https://github.com/ng-bootstrap/ng-bootstrap/blob/master/src/accordion/accordion.ts#L131