我在使自定义过滤器正常工作时遇到问题。
我有一个全局过滤器模块:
angular.module('globalFilters', []).filter('dateRange', function () {
return function(item) {
console.log(item);
return true;
}
});
这会在创建时注入(inject)到我的应用程序中。 我正在尝试将其应用于 ng-repeat:
tr.pointer(ng-repeat="asset in completed | dateRange", ng-animate="'animate'", ng-click="selectAsset(asset);")
td {{asset.Name}}
但是,添加此过滤器将从表中过滤掉所有 Assets
。为了尝试隔离问题,我为显示所有 Assets 的函数返回 true,但它不起作用。
将item
记录到控制台后,结果似乎是所有assets
的数组,所以我猜有问题。
我正在关注本教程 https://docs.angularjs.org/tutorial/step_09
谢谢!
最佳答案
您正在过滤一个数组...因此您的过滤函数需要返回一个数组。
.filter('dateRange', function () {
return function(itemArray) {
if(!itemArray){
return null
}else{
return itemArray.filter(function(item){
// conditions of filter
});
}
}
});
关于javascript - angularJS全局过滤模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34958408/