Ede Ede - 12 days ago 9
AngularJS Question

Can I reuse the key from ng-repeat in a model?

I'm trying to reuse the key from the ng-repeat for the model of the input field ng-model="...key.percent".

Something like this:

<div ng-repeat="(key, val) in $ctrl.offer.properties">
<fieldset ng-if="val">
<h3>{{$ctrl.getLabelFor(key)}}</h3>
<md-input-container>
<input name="procent" ng-model="$ctrl.offer.properties.key.procent"/>
</md-input-container>





I want to keep my properties as they are.

Is there a way to do this?

Answer

Sure, you can access it via key by wrapping key inside [] like below.

ng-model="$ctrl.offer.properties[key]procent"