Reputation: 297
I am a beginner in Angular 2.I'm trying to display some data using angular. this is my code part
<span> Wages</span><span>{{(Wages|currency:USD$:2)}}</span>
above part will display as "Wages $0.00" . Its OK but if there is no value or null in "wages" then it should not display any thing .only need to show "Wages"
How can i do that?. I tried some thing below and its not working
<span> Wages</span><span>{{(Wages|currency:USD$:2)||' '}}</span>
Thanks in advance
Upvotes: 0
Views: 1416
Reputation: 161
you can simply go for ternary operator like
{{ Wages !== 0 ? (Wages | currency: USD$: 2) : ' ' }}
Upvotes: 0
Reputation: 4848
You can do the following:
<span> Wages</span><span *ngIf="Wages">{{(Wages|currency:USD$:2)||' '}}</span>
This will only render the <span>
if the Wages
object has a value
Upvotes: 3
Reputation: 105
if you make a function in your view, then it becomes easier to do logic in your controller
{{ mySpecificThing(String1) }}
... then in controller define the function to get what you need
Upvotes: 0
Reputation:
I think this sould have worked ... Try this ?
{{(Wages || '') | currency:USD$:2}}
By the way, is your Wages
a string, a number ... ?
Upvotes: 0