10

I have two questions.

  1. how to pass param to a filter function.

    say for example: item in masterData|filter1:masterdata|filter2:outputFromfilter1, myparam | filter3:outputFromfilter2, myparam1,myparam2

  2. how to access the controller $scope inside the filter function.

    animateAppModule.filter( 'distinct' , function(){
        return function(masterdata){
            //HOW TO ACCESS THE $scope HERE
        }
    })
    

Here is a fiddle. Pls. look in to the firebug console, to see that the parameters passed to the filter is undefined.

1 Answer 1

30

For your 1st question:

You can give parameters separated by : into the filter. For example,

{{ array | myfilter:a:b:c }}

In your filter definition,

angular.module('app', []).
  filter('myfilter', function() {
    return function(in, param1, param2, param3) {
      // do something
    };
  });

for your 2nd question.

Not sure why you need to access $scope. Can you simply feed whatever needed information via param as your Q1?

Sign up to request clarification or add additional context in comments.

3 Comments

It looks like working for me (plnkr.co/edit/PVSEqp). You may want to check whether your distinctGrades is really defined OK.
Thanks, it worked. But i could not pass $scope in the param.
You could pass this in the filter as in the expression in the template, this is the $scope in the controller. But I do not think it is a good practice as your filter will be dependent on $scope structure/state.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.