AngularJS 获取ng-repeat的动态ng-model

首先ng-model设置为$parent.conf[$index]:

  1. 用$parent的原因是ng-repeat产生的,他会为每一个input生成一个子scope对象,而$parent表示用父类的scope,这样我们在JS文件中才能取到该值。
  2. $index代表的意思是ng-repeat="param in params"遍历时的下标
  3. conf是我们在js中的变量名实际效果
<label>
    <input type="checkbox" ng-click="checkSuspectAll(data,$index)" 
              ng-model="$parent.conf[$index]"> {{data.groupName}}</label>

  在controller中定义了一个$scope.conf = [];就是一个数组,通过 scope.conf 把 ng-model 的所有元素自动保存

$scope.checkSuspectAll = function(data,$index) {
                        var item =  data.suspectList;
                        if($scope.conf[$index]) {
                            ... ...
                        }else{
                            ... ...
                        }
                    };
原文地址:https://www.cnblogs.com/miny-simp/p/7773982.html