我有两个问题。
如何传递参数给过滤功能。
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
.
您可以通过给分隔的参数:
进入过滤器。例如,
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?
Not sure why you need to access $scope
.
Can you simply feed whatever needed information via param as your Q1?