3

I found the way pipe under condition here

How can I check the type is number and give it pipes?

{{(item).isNumber ? (item | currency: 'USD':true:'1.2-2') : (item)}}

like this.

ps. I'd not like to use custom pipe decoration.

Any good ideas? Thanks

Community
  • 1
  • 1
Daisy
  • 89
  • 2
  • 9

1 Answers1

4

You can only use methods and objects that are available from within your component class. So no native Javascript functions are available in the string interpolation.

You can however write a helper method in your component (taken from this post):

isNumber(o): boolean {
  return ! isNaN (o-0) && o !== null && o !== "" && o !== false;
}

And use it like this:

{{ isNumber(item) ? (item | currency: 'USD':true:'1.2-2') : (item) }}
Community
  • 1
  • 1
Maximilian Riegler
  • 22,720
  • 4
  • 62
  • 71