[英]angularjs Hide objects with certain class when checkbox is checked
I've looked up the ng-show directive but none of the examples seemed to fit my case. 我已经查看了ng-show指令,但是这些示例似乎都不适合我的情况。
I have a certain amount of divs with the class 'foo' which is dynamically generated based on some logic. 我有一定数量的类'foo'的div,它是基于某些逻辑动态生成的。 I want to hide all the divs with that class when a checkbox is selected.
我想在选中复选框时隐藏该类的所有div。
edit: 编辑:
I solved it with this 我用这个解决了
<input type="checkbox" ng-model="hideClosed" checked>
<div ng-show="{{location.isOpen}}" ng-hide="hideClosed && {{!location.isOpen}}"></div>
Only problem now is that the checkbox does not start initially checked. 现在唯一的问题是,该复选框最初并未启动。 I tried adding ng-checked="true" to the checkbox, but it didn't hide the closed ones until it was un-checked and checked again.
我尝试将ng-checked =“ true”添加到复选框,但是直到取消选中并再次检查它,它才隐藏隐藏的复选框。
You could try giving each of the divs the ng-show
attribute when they are dynamically generated. 您可以尝试在每个div动态生成时为它们赋予
ng-show
属性。 This will make them automatically hide or show depending on the model. 这将使它们根据模型自动隐藏或显示。
Then you can use the ng-checked
attribute on the checkbox to bind the "checked" state of checkbox to the value in the model that shows and hides the elements. 然后,您可以在复选框上使用
ng-checked
属性,将复选框的“ checked”状态绑定到模型中显示和隐藏元素的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.