Issue
I have a pipe class which returns data based on the arguments you are passing. I know how to use it in my template HTML using the |
symbol, but I want to use it in my component too.
Is there a way to call a pipe directly from inside a component or a service in Angular 2?
Solution
You can call your pipe directly in your code by using:
YourPipeClass.prototype.transform(value, arg1, arg2);
You can call it from inside your component or from anywhere else that imports it.
There is also the new
way:
new SortTodosPipe().transform(value, arg1, arg2);
But keep in mind it will create an object, so either save that object for later use or use the prototype
method.
Anyway you choose, you must add the pipe to your providers
if you use it inside a component, like so:
@NgModule({
providers: [YourPipe]
})
Answered By - Eran Shabi
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.