如何传递参数在JS角过滤功能参数、功能、JS

2023-09-14 23:07:14 作者:中国好胖子

我有两个问题。

如何传递参数给过滤功能。

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?