如何传递参数在JS角过滤功能 [英] how to pass param to a filter function in angular js
本文介绍了如何传递参数在JS角过滤功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个问题。
-
如何传递参数给过滤功能。
how to pass param to a filter function.
比方说:在masterData项目|过滤器1:masterdata |过滤器2:outputFromfilter1,myparam |过滤器3:outputFromfilter2,myparam1,myparam2
如何访问过滤函数内部控制器 $范围
。
how to access the controller $scope
inside the filter function.
animateAppModule.filter( 'distinct' , function(){
return function(masterdata){
//HOW TO ACCESS THE $scope HERE
}
})
下面是一个小提琴。 PLS。来看一下,Firebug控制台,看看传递给过滤器的参数是未定义
。
Here is a fiddle. Pls. look in to the firebug console, to see that the parameters passed to the filter is undefined
.
推荐答案
您可以通过给分隔的参数:
进入过滤器。
例如,
For your 1st question:
You can give parameters separated by :
into the filter.
For example,
{{ array | myfilter:a:b:c }}
在过滤器定义,
angular.module('app', []).
filter('myfilter', function() {
return function(in, param1, param2, param3) {
// do something
};
});
为您的第二个问题。
不知道为什么你需要访问 $范围
。
你可以简单地喂任何需要的信息通过参数作为Q1?
for your 2nd question.
Not sure why you need to access $scope
.
Can you simply feed whatever needed information via param as your Q1?
这篇关于如何传递参数在JS角过滤功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文