Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Chevron icon to ngx-bootsrap accordion

I have a problem changing the chevron from UP to DOWN when clicking the accordion. It seems to always result to true no matter what trick I tried and even tried other examples like this https://stackblitz.com/edit/ngx-bootstrap-ifmpph?file=app%2Fapp.component.html

        <accordion [closeOthers]="true">
                <accordion-group #group [isOpen]='true'>
                    <div accordion-heading class="clearfix">
                        Basic Information
                        <span class="badge badge-secondary float-right pull-right">
                            <i class="fa" [ngClass]="!group?.isOpen ? 'fa-chevron-down': 'fa-chevron-down'"></i>
                        </span>
                    </div>
                </accordion-group>
            </accordion>
like image 854
Andrew Rutazamba Avatar asked Feb 13 '18 21:02

Andrew Rutazamba


2 Answers

this one works:

  <accordion>
      <accordion-group #group1 [isOpen]='true'>
        <div accordion-heading class="clearfix">
        Basic Information
          <span class="badge badge-secondary float-right pull-right">
            <i class="fa" [ngClass]="{'fa-chevron-up': group1.isOpen, 'fa-chevron-down': !group1.isOpen}"></i>
          </span>
        </div>
  </accordion>
like image 122
Wei Avatar answered Nov 15 '22 04:11

Wei


I'm not sure if this is a best solution, but it is working for me:

   <ngb-accordion #accordion [closeOthers]="true" >
    <ngb-panel *ngFor="let round of data, let i=index">
      <ng-template ngbPanelTitle>
        <div class="d-flex flex-row justify-content-between" style="width: 100%">
          <div class="p-2">
            {{round.title}}
          </div>
          <div class="p-2">
            <span [ngClass]="{'icon-arrow-up': accordion.panels._results[i].isOpen, 'icon-arrow-down': !accordion.panels._results[i].isOpen}"></span>
          </div>
        </div>
      </ng-template>
      <ng-template ngbPanelContent>
        {{round.info}}
      </ng-template>
    </ngb-panel>
  </ngb-accordion>

Take a look to accordion.panels._results[i].isOpen. Also, add to component.ts:

   import { AccordionComponent } from 'ngx-bootstrap';
   ...
   @ViewChild('accordion') accordion: AccordionComponent;
like image 2
undejavue Avatar answered Nov 15 '22 03:11

undejavue