Hongbo Miao Hongbo Miao - 4 months ago 22
TypeScript Question

Is it possible to use pipe in the code in Angular 2?

When I use my custom pipe in template, it is like this. And it works well.


Is it possible to use pipe in the code? I try to use like this,

let name = `${user|userName}`;

But it shows

userName is not defined

My alternative way is using db.collection.findOne() manually in the code. But is there any smart way?


@Siva is correct. And thanks!

So the way to use the pipe in the component is like this:

let name = new UserNamePipe().transform(user);

Link to another similar question.