In AngularJS, is it possible to add the ng-repeat $ index to the property name of the ng-model directive?

Is it possible to add the ng-repeat $ index to the value of the ng-model directive?

<div class="row" ng-repeat="item in GiantList"> <input type="text" value="" ng-model="saveData.MyProperty+[$index+1]"> </div> 

Ideally, this means that:

$ scope.saveData = [{"MyProperty1": "Bob"}, {"MyProperty2": "Sam"}, {"MyProperty3": "Chris"}]

I have tried every syntax combination that I can think of to no avail.

Thank you very much!

+6
source share
2 answers

Try

 <input type="text" value="" ng-model="saveData['MyProperty'+($index+1)]"> 

Demo: Fiddle

+11
source

I'm not sure I understood your question, but I will try the following:

http://plnkr.co/edit/3qClmN

 saved[$index]['friend'+($index+1)] 
+2
source

All Articles