Dynamically assign element id inside ngFor

You can use {{ 'wave' + i }} instead of wave{{i}}. Make it as Angular Experession. This is the full ngFor:

<li *ngFor="let episode of episodes; let i = index">
     <div id="{{ 'wave' + i }}"></div>

It works and creates the div with the correct id


Output will be like this:

<div id=​"wave1">​wave1​</div>

but remember your code will start from wave0 as i = index starts from 0.

Leave a Comment