嵌套的ng-repeat在<input />

时间:2016-02-29 17:44:34

标签: javascript angularjs angularjs-ng-repeat

我有一个$scope参数,如下所示:

$scope.filters = [{name: "Brands", brands: ['Brand1', 'Brand2', 'Brand3']}, 
                 {name: "Catalogs", brands: ['Cat1', 'Cat2', 'Cat3']}];

在html文件中,我尝试将其显示为如下列表:

<div ng-repeat="filter in filters"><h3>{{filter.name}}</h3>
            <input type="checkbox" ng-repeat="brand in filter.brands"> {{brand}}<br>
        </div>

filter.name"Brands" "Catalogs"正常工作,但在其下方我看到了空的复选框。 让它工作的唯一方法是从输入中取出ng-repeat并将其放在标签之外。
我在这里错过了什么吗?

1 个答案:

答案 0 :(得分:1)

像这样

var app = angular.module("app",[]);
app.controller("ctrl" , function($scope){
  $scope.filters = [{name: "Brands", brands: ['Brand1', 'Brand2', 'Brand3']}, 
                 {name: "Catalogs", brands: ['Cat1', 'Cat2', 'Cat3']}];
  
  })
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app="app" ng-controller="ctrl">
<div ng-repeat="filter in filters"><h3>{{filter.name}}</h3>
     <div  ng-repeat="brand in filter.brands">
        <input type="checkbox" ng-model="brands"> {{brand}}<br>
     </div>
    </div>
  
  </div>