Hongbo Miao Hongbo Miao - 1 year ago 66
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?

Answer Source

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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download