Angular-ng-repeater中的动态ng-model [英] Angular - Dynamic ng-model inside ng-repeater

查看:97
本文介绍了Angular-ng-repeater中的动态ng-model的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于搜索数据的表格,某些字段是在ng-repeat内动态生成的.问题是将ng-model分配给我必须进行搜索的所有字段.

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.

我需要将{{masterAttribute.Name}}用作ng-model,或在搜索中可以读取的任何内容.

I need to use the {{masterAttribute.Name}} as ng-model, or whatever that i can read to do in my search.

HTML是

<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> 

推荐答案

ng-model="{{masterAttribute.Name}}"更改为ng-model="masterAttribute.Name".

因为它已经在Angular范围内,所以不需要插值运算符( {{..}} ).

since it's already in Angular scope, so no need of interpolation operator({{..}}).

另外:search()方法是ricercaAttivita控制器的一部分,因此您也可以在控制器中访问masterAttributes.在那里您可以找到所有Name道具.

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.

这篇关于Angular-ng-repeater中的动态ng-model的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆