Abdelhadi Lahlou
Abdelhadi Lahlou

Reputation: 525

Increment input ID Angularjs

I'm looking to increment my input ID while using ng-repeat and I tried this but it doesn't work :

<div ng-repeat="d in index">

<input type="checkbox" name="name" value="" id="{{d}}" ng-model="{{d}}"/>

</div>

Do you have any ideas about how to do it?

Upvotes: 3

Views: 276

Answers (2)

Vipin Jain
Vipin Jain

Reputation: 3756

Try This

<div ng-repeat="d in index track by $index">

<input type="checkbox" name="name" value="" id="{{$index}}" ng-model="d"/>

</div>

dynamic id ng-repeat

Upvotes: 1

Ruben Karapetyan
Ruben Karapetyan

Reputation: 469

you can track by $index your ng-repeat

div ng-repeat="d in index track by $index"
  input type="checkbox" name="name" value="" id="{{$index}}" ng-model="{{d}}"/
/div

Upvotes: 2

Related Questions