0

A similar question was answered, but I cannot find out why the code is not working for me. I have a list of ngbpanels generated using ngFor. I need to expand/de-expand a specific panel according to some logic

In the html file

<ngb-accordion #acc="ngbAccordion" >
<ngb-panel *ngFor="let panel of panels; let panelIndex=index" id="{{panelIndex}}">
....

In the ts file:

@ViewChild('acc') panelsView;
....
this.panelsView.toggle(this.panelIndex);

The panel is open and by writing that code I wish it would toggle under specific condition. The code does not give me any errors but the panel stays open

Donia Zaela
  • 317
  • 1
  • 4
  • 15
  • So what does the `toggle` function look like? – user184994 May 29 '18 at 17:14
  • Isn't there an associated function called "toggle" as there is click() for a button? Here (https://ng-bootstrap.github.io/#/components/accordion/examples), it just used toggle() without declaring it. Am I missing something here. – Donia Zaela May 29 '18 at 19:08
  • I know where the problem is now, the issue is that toggle would take a string like this: .toggle('panelId'), where panelId is the real string representing the id of the panel. The issue is that I want to pass a variable. I tried .toggle(" '+this.panelIndex+' "), but it did not work, any suggestions? – Donia Zaela May 30 '18 at 13:20
  • What's wrong with passing a variable the way you were doing? If you `console.log(this.panelIndex)`, does it print the value you're expecting? – user184994 May 30 '18 at 17:08

0 Answers0