I have to implement an Accordion in Angular6 and I want to know what link I have clicked to add a class to it or remove it with Typescrypt since I can't use Jquery. Any ideas.
(click)="accordionFunction(this);
"
I have to implement an Accordion in Angular6 and I want to know what link I have clicked to add a class to it or remove it with Typescrypt since I can't use Jquery. Any ideas.
(click)="accordionFunction(this);
"
To do this you have to create a child component (div) which carries the selection functionality:
With the boolean property "selected" we will keep whether it is selected or not, and ngClass will assign the class "selected" in case the property "selected" is true.
The parent component should simply load the child as many times as we want:
If we only want to select one, we could modify the child component by adding an eventemitter that is launched when the selection is executed:
And the parent component will listen to all the events of the child components of type AccordionDiv so that it only allows selecting the current one:
An executable example: https://next.plnkr.co/edit/8htQBguMf3zEH48X?open=lib%2Fapp.ts&deferRun=1