Mark Mark - 1 year ago 145
HTML Question

Angular ng-if ternary operator in one span?

So am trying to use a ternary operator to combine 2 spans as:

<span ng-if="customer != null">{{ customer }}</span><span ng-if="customer == null">[customer]</span>

The switch is just based on if an id has a value or not in an input elsewhere in the form. Suggestions?

Thanks much.

Answer Source

do you mean something like:

<span>{{ (customer != null) ? customer : '[customer]' }}</span>

could also be written as:

<span>{{ customer || '[customer]' }}</span>
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download