0

I am writing a common control that will be used to format data inside a grid. It has 2 parameters that user can set:

  • filter (string) that is used to format value
  • parameters (any[]) that are used by the filter

In the code I am going to call $filter(filter)(value, ...) - here is my problem. How do I pass my parameters? Each filter can have from no parameters to who knows how many. So, is there a nice way to pass variable number of parameters in Angular? So far I did not run into a way of doing it.

1 Answer 1

1

You should be able to do:

$filter(filter).apply(this, parameters)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks! For some reason I did not think about it.
In fact it does not work, I just did not catch it. One of my filters takes 2 parameters: a number and a boolean, So, my parameters array looks like [3, true]. Passing it as a second parameter to $filter does not work.
This is why you need to use apply, which is expecting an array of parameters for second argument.

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.