Hongbo Miao Hongbo Miao - 1 month ago 6
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.

{{user|userName}}


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?

Answer

@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.