如何在ngx-bootstrap手风琴中添加折叠图标

时间:2018-12-05 20:06:04

标签: css angular twitter-bootstrap ngx-bootstrap ngx-bootstrap-accordion

在使用Angularngx-bootstrap应用中,我想添加一个折叠图标,该图标可以反映accordion(折叠/展开)的状态,如下所示:

enter image description here

enter image description here

4 个答案:

答案 0 :(得分:1)

您基本上可以在CSS中执行此操作:

.accordion-toggle[aria-expanded="true"]:before {
    content: "\f107";
    font: normal normal normal 14px/1 FontAwesome;
}

.accordion-toggle[aria-expanded="false"]:before {
    content: '\f106';
    font: normal normal normal 14px/1 FontAwesome;
}

只需使用您喜欢的图标的字体来为before选择器设置样式...

答案 1 :(得分:1)

您可以使用accordion-group输入isOpen

HTML

<accordion-group [isOpen]="isContentOpen">
  <button class="btn btn-light float-right">
    <i *ngIf="isContentOpen" class="fas fa-caret-up">Open</i>
    <i *ngIf="!isContentOpen" class="fas fa-caret-down">Close</i>
  </button>
</accordion-group>

TS

isContentOpen: boolean = false;

我建议安装https://fontawesome.com/

答案 2 :(得分:1)

这是对我有用的解决方案

<accordion-group [isOpen]="false" #myGroup>
  <button class="btn btn-light float-right">
    {{ myGroup?.isOpen ? 'Opened' : 'Closed' }}
    <i class="fas" [ngClass]="{'fa-caret-down': myGroup?.isOpen, 'fa-caret-up': !myGroup?.isOpen}"></i>
  </button>
</accordion-group>

答案 3 :(得分:1)

以下答案适用于ngx-bootstrap@5.x.x。还为希望使用不同于FontAwesome的用户解决了该问题:

<!-- Please note that the #accordionGroupRef is scoped! -->
<accordion-group
    *ngFor="let number of [1,2,3,4];"
    [isOpen]="false"
    #accordionGroupRef
>

    <!-- Header -->
    <h5 class="m-0" accordion-heading>
        {{ accordionGroupRef.isOpen ? "OPEN" : "CLOSED"}}
        I am accordion {{number}}
        <span class="float-right"> I float all the way on the right!</span>
    </h5>    

    <!-- Content -->
    Accordion content
</accordion-group>