Radoslav Stoyanov Radoslav Stoyanov - 1 year ago 145
TypeScript Question

Angular2 - assign pipe from a variable

Is it possible something like this:

{{property | some_variable_name}}

My goal is to use a
that is set in a
configuration (or a variable), but I'm not sure if it is possible to pass the
name in the interpolation this way.

Anybody tried something like this before?

Answer Source

The pipe needs to be listed in pipes: [MyPipeHere] in the @Component() decorator or in PLATFORM_PIPES, therefore this approach won't work.

What you can do instead is creating a custom pipe that calls other "pipes". A pipe is basically just a function, therefore this is easy.

You can pass a variable to your custom pipe like

{{property | my_custom_pipe:some_variable_name}}

this should be pretty close to what you want.

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