• Skip to main content
  • Skip to primary sidebar

Web Development Archive

  • Archive
You are here: Home / Angular / Add class only the clicked item of an array (Accordion)

Add class only the clicked item of an array (Accordion)

Templaten belül ezeket kéne módosítani:

(click)="onGroupClick(i)" -> itt átadjuk hogy melyik group lett kattintva

[class.open]="isGroupOpen(i)" -> megnézzük hogy a nyitott group-ok között ott van-e az adott group

komponensen belül pedig:

private openGroups: number[] = [];

public isGroupOpen(index: number): boolean { return this.openGroups.includes(index); }

public onGroupClick(index: number): void { 
    if (this.isGroupOpen(index)) { 
        this.openGroups = this.openGroups.filter(group => group !== index) 
    } else { 
        this.openGroups.push(index); 
    } 
} 

Filed Under: Angular

About Gabor Flamich

I'm a web developer and designer based in Budapest, Hungary. In recent years, I've documented hundreds of solutions I came across during development. This site is an archive for useful code snippets on WordPress, Genesis Framework and WooCommerce. If You have any questions related to WordPress development, get in touch!

Primary Sidebar

  • angular.io
© 2026 WP Flames - All Right Reserved