I’m new to angular framework and I have a performance problem with nested *ngFor loops used to display hierarchical data.
- *ngFor - 10 Items ( Level 1 ) extension panel for each item
- *ngFor 10 Items ( Level 2 ) grid list to display the content
- *ngFor 5 Items (Level 3 ) 5 button toggles and 2 select controls
To avoid loading all the data, I’m setting the collection for 2nd *ngFor based on current opened panel from level 1.
The entire page is very slow when I’m expanding a panel or when I’m trying to press a button toggle. Note: I do not change the collections with these actions.
For debugging, I put a function in each ngFor to return the collections. I saw that each time I press a button toggle, angular is redoing all the iterations in all *ngFor directives multiple times.
I don’t understand why all the iterations are necessary each time I change a control. How can I improve performance in this case?
Code sample reproducing the problem on stackblitz!