AngularJS: How to use ternary operator in template

AngularJS now supports a ternary condition in its expressions. The basic syntax is as below.

Let’s see some examples.

Above expression will check if there is a value set in bioText variable and prints its value if not empty otherwise “N/A”.

You can also use this expression with attributes like ng-if or ng-show. See below examples.

You can also use multiple checks in condition part like,



Please note that ternary operators will work on AngularJS 1.5 and above only.

You may also like...