Hemalatha Dirisala
Hemalatha Dirisala

Reputation: 19

can we append the string with a variable in the ng-model?

<div ng-repeat="data in assets">
    <input type="checkbox" ng-model="text"+{{$index}}/>
</div>

here I want to generate different ng-models for each checkbox

Upvotes: 0

Views: 989

Answers (2)

Rjun
Rjun

Reputation: 406

You can use alias name "data" and assign "data.isChecked" to ng-model.

<div ng-repeat="data in assets">
    <input type="checkbox" ng-model="data.isChecked" />
</div>

This will add that "isChecked" variables at run time to all objects of "assets" array.

Upvotes: 4

It's better to have your models in the array you are looping over.

<div ng-repeat="data in assets">
    <input type="checkbox" ng-model="data.input"/>
</div>

Upvotes: 0

Related Questions