Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In AngularJS, can I append a ng-repeat $index to the property name of a ng-model directive?

Tags:

angularjs

Is there anyway to append the ng-repeat $index to the value of a ng-model directive?

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

Ideally, this would mean that:

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

I've tried every syntactical combination I can think of to no avail.

Many thanks!

like image 713
Hairgami_Master Avatar asked Mar 28 '13 03:03

Hairgami_Master


1 Answers

Try

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

Demo: Fiddle

like image 121
Arun P Johny Avatar answered Dec 09 '22 06:12

Arun P Johny