How to dynamically change HTML id using angularJs

Inside ng-repeat, I want to do something like this:

<div class='col-sm-12' id="playerHolder"><span id="vidPlayerDIV{{$index}}"></span></div> 

If divs are named vidPlayerDiv0, vidPlayerDiv1, etc.

However, this code does not work. How can i do this?

+6
source share
3 answers

You can try the following:

 id="{{'vidPlayerDiv' + $index}}" 
+7
source

I am creating a JSFiddle with the correct operation.

  <div ng-repeat='item in items'> <span id="{{'vidPlayerDiv' + $index}}">{{'vidPlayerDiv' + $index}}</span> </div> 
+5
source

This exact code worked for me, at least there should be an error in your code.

  <div ng-repeat="number in numbers"><div class="box{{$index}}">Hello </div></div> 
0
source

All Articles