So I have a pipe like this:
<ul *ngFor="#eachNumber of (NumberArray | MyPipe: '1')"></ul>
How can I assign the returned result of the pipe to a variable that can be used elsewhere in my code?
I've looked for a while and read about something called assign-local but couldnt find much information on it. Is there a obvious way to do this that I am just missing?
In your component's template you can use multiple arguments by separating them with colons: {{ myData | myPipe: 'arg1':'arg2':'arg3'... }} Pipes take an array that contains all arguments, so you need to call them like this: new MyPipe().
You don't have to duplicate your code if you want to also use a pipe's functionality in a component class. All you have to do really is inject the pipe like a service, and then call its transform method.
Pipes are simple functions to use in template expressions to accept an input value and return a transformed value. Pipes are useful because you can use them throughout your application, while only declaring each pipe once.
Just in case anyone stumbled upon this question. This is possible with Angular 4 now, with the updated as
syntax :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With