Angular - Dynamic ng-model inside ng-repeater

旧街凉风 提交于 2019-12-12 04:57:23

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!