I know I can call a pipe like this:
{{ myData | date:'fullDate' }}
Here the date pipe takes only one argument. What is the syntax to call a pipe with more parameters, from component's template HTML and directly in code?
I know I can call a pipe like this:
{{ myData | date:'fullDate' }}
Here the date pipe takes only one argument. What is the syntax to call a pipe with more parameters, from component's template HTML and directly in code?
You're missing the actual pipe.
Multiple parameters can be separated by a colon (:).
Also you can chain pipes, like so:
In your component's template you can use multiple arguments by separating them with colons:
From your code it will look like this:
And in your transform function inside your pipe you can use the arguments like this:
Beta 16 and before (2016-04-26)
Pipes take an array that contains all arguments, so you need to call them like this:
And your transform function will look like this:
Since beta.16 the parameters are not passed as array to the
transform()
method anymore but instead as individual parameters:https://github.com/angular/angular/blob/master/CHANGELOG.md#200-beta16-2016-04-26
I use Pipes in Angular 2+ to filter arrays of objects. The following takes multiple filter arguments but you can send just one if that suits your needs. Here is a StackBlitz Example. It will find the keys you want to filter by and then filters by the value you supply. It's actually quite simple, if it sounds complicated it's not, check out the StackBlitz Example.
Here is the Pipe being called in an *ngFor directive,
Here is the Pipe,
And here is the Component containing the object to filter,
StackBlitz Example
GitHub Example: Fork a working copy of this example here
*Please note that in an answer provided by Gunter, Gunter states that arrays are no longer used as filter interfaces but I searched the link he provides and found nothing speaking to that claim. Also, the StackBlitz example provided shows this code working as intended in Angular 6.1.9. It will work in Angular 2+.
Happy Coding :-)