检查是否通过滤波器角JS返回的任何值 [英] to check whether any value returned by filter in angular js
本文介绍了检查是否通过滤波器角JS返回的任何值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在那里有一个过滤器正在使用过滤视图:test_id 。它是工作绝对fine.What我想要做的是,如果搜索筛选器不返回任何数据我可以调用一个函数在时间的那一瞬间,当过滤器返回null或列表中的数据显示为每个搜索。控制器
<输入类型=文本ID =test_idNG模型=test_idVALUE =/>< DIV CLASS =test_list>
< UL>
&所述p为H.; testID:{{test_id}}&下; / P&GT - →;
<李NG重复=试验test_list |过滤器:test_id>
{{测试}}
< /李>
< / UL> < / DIV>
解决方案
试试这个。
在控制器
$ scope.filteredData = $ scope.data = [1,2,3,4,5,6,7,8,9,10]; //虚拟数据$ scope.applyFilter =功能(){
$ scope.filteredData = $ $范围的eval(数据|过滤器:filterWith');。 如果(!$ scope.filteredData ||!$ scope.filteredData.length){
// 没有数据。
//做你的东西。
}
}
在您的标记
<输入类型=文本NG模型=filterWithNG变化=applyFilter()会>
< DIV数据-NG-重复=项filteredData>
{{项目}}
< / DIV>
I have a view where a filter is being used filter: test_id.It is working absolutely fine.What I want to do is if the search filter does not return any data can I call a function in the controller at that instant of time when the filter returns null or no data in the list is shown as per search.
<input type="text" id="test_id" ng-model="test_id" value=""/>
<div class="test_list">
<ul>
<p> testID :{{test_id}}</p>-->
<li ng-repeat="test in test_list | filter: test_id">
{{test}}
</li>
</ul>
</div>
解决方案
Try this.
In your controller
$scope.filteredData = $scope.data = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; // dummy data
$scope.applyFilter = function () {
$scope.filteredData = $scope.$eval('data | filter: filterWith');
if (!$scope.filteredData || !$scope.filteredData.length) {
// no-data.
// do your stuff.
}
}
In your markup
<input type="text" ng-model="filterWith" ng-change="applyFilter()">
<div data-ng-repeat="item in filteredData" >
{{item}}
</div>
这篇关于检查是否通过滤波器角JS返回的任何值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文