Angular 我无法使用ngbAccordion方法对孩子ngbAccordion进行测试 ★ [{{children2.id}]{{children2.name}★; +{{children2.price}} 近亲 近亲

Angular 我无法使用ngbAccordion方法对孩子ngbAccordion进行测试 ★ [{{children2.id}]{{children2.name}★; +{{children2.price}} 近亲 近亲,angular,twitter-bootstrap,user-interface,ng-bootstrap,Angular,Twitter Bootstrap,User Interface,Ng Bootstrap,在这种情况下,Closeparent按钮工作正常 不关闭儿童按钮。您需要获得“父母”和“孩子”的一致性。为此,使用ViewChildren 在你的 <ngb-accordion #accord="ngbAccordion"> <ngb-panel *ngFor=" let children of laptop.children; let index = index" id="static-{{index}}" title="[{{children.id}}] - {{ch

在这种情况下,Closeparent按钮工作正常 不关闭儿童按钮。

您需要获得“父母”和“孩子”的一致性。为此,使用ViewChildren

在你的

<ngb-accordion #accord="ngbAccordion">
  <ngb-panel  *ngFor=" let children of laptop.children; let index = index" id="static-{{index}}" title="[{{children.id}}] - {{children.name}}">
    <ng-template ngbPanelContent>
        <ngb-accordion #childaccord="ngbAccordion">
            <ngb-panel  *ngFor=" let children2 of children.children; let index2 = index" [disabled]="false"   id="static2-{{index2}}" >
              <ng-template ngbPanelTitle>
                  <span>&#9733; <b>[{{children2.id}}]</b> {{children2.name}} &#9733;
                    <div style="float:right; border: solid 0.3em; border-color: gold;">+{{children2.price}}€</div>
                  </span>
              </ng-template>
            </ngb-panel>
          </ngb-accordion>
    </ng-template>
  </ngb-panel>
</ngb-accordion>

<button (click)="accord.closeAll()">CloseParent</button>

<button (click)="childaccord.closeAll()">Closechild</button>
@ViewChildren('accord')家长:QueryList
@ViewChildren('childaccord')子对象:QueryList
closeAllParent()
{
this.parents.forEach(x=>x.collapseAll())
}
closeAllChildren()
{
this.children.forEach(x=>x.collapseAll())
}
请参见中的示例

注意:第七章,如果你提供更多的线索,甚至你创建了一个stackblitz,那么尝试帮助会更容易

  @ViewChildren('accord')parents:QueryList<NgbAccordion>
  @ViewChildren('childaccord')children:QueryList<NgbAccordion>

  closeAllParent()
  {
    this.parents.forEach(x=>x.collapseAll())
  }
  closeAllChildren()
  {
    this.children.forEach(x=>x.collapseAll())
  }