[英]How to show/hide filer for ng-repeat for AngularJs 1.4.8
I got a list of messages with filter: 我得到了带有过滤器的消息列表:
<tr ng-repeat="message in messages | filter:searchForMessage">
and this is a button: 这是一个按钮:
<a href="#" ng-click="search()">
<img src="../common/magnifier.png">
</a>
but I would like to hide/show this filter only on click on the Search button: 但我只想在单击“搜索”按钮时隐藏/显示此过滤器 :
$scope.showSearchPanel = false;
$scope.search = function(){
$scope.showSearchPanel = !$scope.showSearchPanel;
}
Are there any way how I could do that? 有什么办法可以做到吗? Thank you! 谢谢!
You can use 您可以使用
<tr ng-if="showSearchPanel" ng-repeat="message in messages | filter:searchForMessage">
It will show after clicking on search button 点击搜索按钮后将显示
You could add the variable in the filter to switch it on and off. 您可以在过滤器中添加变量以将其打开和关闭。
<tr ng-repeat="message in messages | filter:searchForMessage: showSearchPanel">
Then inside the filter you can validate if "showSearchPanel" return filtered results otherwise return same results 然后,您可以在过滤器内部验证“ showSearchPanel”是否返回过滤结果,否则返回相同结果
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.