How would I have multiple cases in an *ngIf
statement? I\'m used to Vue or Angular 1 with having an if
, else if
, and else
This seems to be the cleanest way to do
if (foo === 1) {
} else if (bar === 99) {
} else if (foo === 2) {
} else {
}
in the template:
foo === 1
bar === 99
foo === 2
else
Notice that it works like a proper else if
statement should when the conditions involve different variables (only 1 case is true at a time). Some of the other answers don't work right in such a case.
aside: gosh angular, that's some really ugly else if
template code...