答案 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;
答案 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>