问题
I have a form for search data, some fields are generated dinamically inside a ng-repeat. The problem is to assign ng-model to all fields that i must get to do the search.
I need to use the {{masterAttribute.Name}} as ng-model, or whatever that i can read to do in my search.
HTML is
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="MyApp" ng-controller="ricercaAttivita">
<div class="accordion-group" ng-repeat="masterAttribute in masterAttributes">
<select class="trip dark" ng-model="{{masterAttribute.Name}}" ng-options="attr.Id as attr.Value for attr in masterAttribute.Values">
<option value="">TUTTE</option>
</select>
</div>
<button class="btn btn-default btn-green btn-3-column sidebar-filtri-button" ng-click="search()">Cerca</button>
</body>
回答1:
Change ng-model="{{masterAttribute.Name}}" to ng-model="masterAttribute.Name".
since it's already in Angular scope, so no need of interpolation operator({{..}}).
Further : search() method is part of your ricercaAttivita controller, then you also have access to masterAttributes as well in controller., you can find all Name props there.
来源:https://stackoverflow.com/questions/44430277/angular-dynamic-ng-model-inside-ng-repeater