There are multiple lists of elements available:
let list1 = [1,2,3,4];
let list2 = [1,2,3,4];
let list3 = [1,2,3,4];
Each list is being iterated through in a loop:
<div *ngFor="let el of list1" (click)="set(el)">{{el}</div>
<div *ngFor="let el of list2" (click)="set(el)">{{el}</div>
<div *ngFor="let el of list3" (click)="set(el)">{{el}</div>
Upon clicking an element within the <div>
, the selected value needs to be stored like so:
selectedFilters = {list1: [1], list2: [2,3], list3: [4]}
Is there a better way to achieve this rather than creating separate classes for each list?
Additionally, the desired output includes converting all selected elements into a JSON format.