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
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) }}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.