How to use labels inside loops with AngularJS

The correct solution is Gleno’s.

$id is guaranteed to be unique for every created scope, while $index changes with any change to the count of the underlining collection.

You need to add the $index property(zero based) that is available on the scope in the repeater

<li ng-repeat="x in xs">
    <form>
       <label for="UNIQUELABEL{{$index+1}}">name</label>
       <input  id="UNIQUELABEL{{$index+1}}">
       <label for="ANOTHERUNIQUELABEL{{$index+1}}">name2</label>
       <input  id="ANOTHERUNIQUELABEL{{$index+1}}">
    </form>
</li>

Leave a Comment