In angular 1 we are having filters, those filters can be used in both DOM and Typescript/Javascript. In Angular 2 we use pipes to do that stuff, but the pipes are accessible to use only in DOM. Is there any other way to use the pipe function in Typescipt (components)? Please help if anyone knows about this.
Example:
<div *for="let item of items">
{{item.price | priceFilter }}
</div>
I created the user defined pipe called priceFilter
but i want to do the same filtering in Javascript/Typescript.
You can use pipe
to filter data in component like this:
let value = new PriceFilterPipe().transform(this.item.price);
I assumed that name of your exported pipe
class is PriceFilterPipe
. Of course, you need to import PriceFilterPipe
in your component as well.
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