Mark Mark - 3 months ago 20
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

do you mean something like:

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

could also be written as:

<span>{{ customer || '[customer]' }}</span>