Angular 4 and 5:
using else :
you can also use then else :
or then alone :
Demo :
Plunker
Details:
The HTML element is a mechanism for holding client-side
content that is not to be rendered when a page is loaded but may
subsequently be instantiated during runtime using JavaScript.
In Angular 4.x.x
You can use ngIf in four way to achieve simple if else procedure:
Just Use If
Using If with Else (Please notice to templateName)
If isValid is false
Using If with Then (Please notice to templateName)
If isValid is true
Using If with Then and Else
If isValid is true
If isValid is false
Tip: ngIf evaluates the expression and then renders the then or else
template in its place when expression is truthy or falsy respectively.
Typically the:
then template is the inline template of ngIf unless bound to a different value.
else template is blank unless it is bound.