2

I am trying to implement accordion functionality without using bootstrap/angular material accordion. My data is coming dynamically from an api.

I tried doing below but that opens and closes all the panels together. I understand the reason behind it but I don't understand how to approach.

Component.ts

export class AccordionComponent implements OnInit {
    isHidden = true;
    mFaqs: IFaq[];
    constructor(private faqService: FaqService) { }

    ngOnInit() {
        this.faqService.getFaqs()
            .subscribe(faqData => this.mFaqs = faqData );
    }

}

component.html

<div class="custom-header" hideToggle="true" (click)="isHidden = !isHidden" *ngFor="let faq of mFaqs?.faqs">
    <section>
        <section>
            Q: {{ faq.question }}
        </section>
        <p [hidden]="isHidden">
            {{ faq.answer }}
        </p>
    </section>

</div>

It should only close/open the clicked one.

1
  • check details summary html tag Commented Jul 16, 2019 at 12:48

1 Answer 1

3

You need to pass unique id for that.

Might be it'll help you.

Angular on click event for multiple items

please go through it.

Sign up to request clarification or add additional context in comments.

1 Comment

Sourav Raj: Huge thanks for your answer! It did work for me :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.