Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign the output of a pipe in angular2 to a variable

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?

like image 754
Witted Avatar asked Dec 23 '15 10:12

Witted


People also ask

How do you pass parameters to a pipe MyPipe?

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().

Can I use pipe in component Angular?

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.

What is pipe () in Angular?

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.


1 Answers

Just in case anyone stumbled upon this question. This is possible with Angular 4 now, with the updated as syntax :)

like image 63
Yiou Avatar answered Sep 28 '22 02:09

Yiou