我需要过滤器1接收一个整数数组。
<select class="form-control"
ng-model="vm.data.form.idService"
ng-options="service.idService as
service.title for service in vm.data.services
| filter: {active: 'true'}
| inArray:vm.data.form.servicesIds:'idService'"></select>
我的自定义过滤器是:
angular.module('mainApp').filter('inArray', function($filter){
return function(list, arrayFilter, element){
if(arrayFilter){
return $filter("filter")(list, function (listItem) {
for (var i = 0; i < arrayFilter.length; i++) {
debugger;
if (arrayFilter[i][element] == listItem[element]){
return true;
}else{
return false;
}
}
return true;
});
}
};
var vm.data.form.servicesIds结果为:{{11,12}},但无效。
此过滤器的目的是接收数组和过滤器,如T-SQL:
SELECT * FROM SERVICES WHERE IdService in (11,12)
这是错误的:
angular.js:13550 Error: [$injector:unpr] Unknown provider: inArrayFilterProvider <- inArrayFilter
http://errors.angularjs.org/1.5.5/$injector/unpr?p0=inArrayFilterProvider%20%3C-NaNnArrayFilter
at http://localhost/Gvisa.Web/assets/lib/angular.js:68:12
at http://localhost/Gvisa.Web/assets/lib/angular.js:4458:19
at Object.getService [as get] (http://localhost/Gvisa.Web/assets/lib/angular.js:4611:39)
at http://localhost/Gvisa.Web/assets/lib/angular.js:4463:45
at Object.getService [as get] (http://localhost/Gvisa.Web/assets/lib/angular.js:4611:39)
at http://localhost/Gvisa.Web/assets/lib/angular.js:19531:24
at isStateless (http://localhost/Gvisa.Web/assets/lib/angular.js:14236:12)
at findConstantAndWatchExpressions (http://localhost/Gvisa.Web/assets/lib/angular.js:14293:33)
at http://localhost/Gvisa.Web/assets/lib/angular.js:14247:7
at forEach (http://localhost/Gvisa.Web/assets/lib/angular.js:322:20)
(anonymous) @ angular.js:13550
提前谢谢
答案 0 :(得分:0)
为什么要在这里注入$ filter
angular.module('mainApp').filter('inArray', function($filter){
不需要。 就像保持它一样
angular.module('mainApp').filter('inArray', function(){
答案 1 :(得分:0)
我认为您在过滤器的最后一行中缺少一个括号
});
答案 2 :(得分:0)
我正在将一个对象与一个简单的数组进行比较。
解决了分号
angular.module('mainApp').filter('inArray', function($filter){
return function(list, arrayFilter, element){
if(arrayFilter){
return $filter("filter")(list, function(listItem){
for (var i = 0; i < arrayFilter.length; i++) {
debugger;
if (arrayFilter[i] == listItem[element])
return true;
}
return false;
});
}
};
});
非常感谢