angularjs 选中复选框时隐藏具有特定类的对象

angularjs Hide objects with certain class when checkbox is checked

本文关键字:对象 复选框 隐藏 angularjs      更新时间:2023-09-26

我查了ng-show指令,但没有一个例子似乎适合我的情况。

我有一定数量的div 和类"foo",它是根据某种逻辑动态生成的。我想在选中复选框时隐藏该类的所有div。

编辑:

我用这个解决了它

<input type="checkbox" ng-model="hideClosed" checked>
<div ng-show="{{location.isOpen}}" ng-hide="hideClosed && {{!location.isOpen}}"></div>

现在唯一的问题是该复选框最初没有启动。我尝试将 ng-checked="true" 添加到复选框中,但它没有隐藏关闭的复选框,直到取消选中并再次选中。

您可以尝试在动态生成每个div 时为其指定 ng-show 属性。 这将使它们根据型号自动隐藏或显示。

然后,您可以使用复选框上的 ng-checked 属性将复选框的"选中"状态绑定到模型中显示和隐藏元素的值。