RRB
RRB

Reputation: 2116

Assign 0 to template if no value is present

I am trying to bind a 0 to my html template if there is no value present from an endpoint. So I have the below in my HTML

${{ amount }}

If amount is not available I would like to show $0 to the user. Is this possible to do in the HTML template or do I have to do a check in my TS file?

Upvotes: 0

Views: 483

Answers (1)

Barremian
Barremian

Reputation: 31105

Angular template interpolations are Typescript expressions. So you could use the || operator

${{ amount || 0 }}

Upvotes: 4

Related Questions