<div class="checkbox"><input type="checkbox" id="1"><label for="1"></label></div>
我要设置复选框的样式,因此必须有一个ID和一个标签,复选框才能正常工作(选中或取消选中)。
我可以通过增量js使用纯js进行设置,但这不是有角度的js方法。我将其放在ngrepeat中,将其视为待办事项列表,如何使其递增?
您可以使用ng-repeat的索引部分,即密钥:
<div class="checkbox" ng-repeat="(index,value) in items">
<input type="checkbox" id="{{index}}"><label for="{{index}}"></label>
</div>
或使用子范围$index
值
<div class="checkbox" ng-repeat="item in items">
<input type="checkbox" id="{{$index}}"><label for="{{$index}}"></label>
</div>
http://plnkr.co/edit/Yh02rAuH40XU0hB4eQO6?p=preview
两种方法之间的区别在于,您假设范围$index
足以满足项目的顺序要求。在该key
方法中,您实际上可以访问items数组上的原始索引(但您也可以在中访问它$scope.item
)
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句