Else

Else is a new construct per Angular 4.0 and is a short hand you can use to help you with conditional statements. Imagine you have the following:

<div *ngIf="hero">
{{ hero.name }}
</div>
<div *ngIf="!hero">
No hero set
</div>

Our use case here is pretty clear; if we have a person set then display its name, otherwise show a default text. We can write this in another way using else:

<div *ngIf="person; else noperson">{{person.name}}</div>
<div #noperson>No person set</div>

What's happening here is how we define our conditional:

person; else noperson

We are saying if person is set then go ahead, if not display the template noperson . noperson   can be applied to a normal HTML element as well as an   ng-template.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset