Reputation: 575
Is there any way to use if elseif else
structure in Angular 2 template?
This is if else
example:
[text]="company ? company.name : 'Select a company'"
I need add elseif
to it.
Upvotes: 0
Views: 948
Reputation: 31
Angular doesn't have if elseif else behaviour yet but you can achieve the same behaviour like below
<!-- showing number divisible by 2 -->
<div *ngIf="number_divide_by(2);else else_if_content1">
Show result of if_content
</div>
<!-- Showing number divisible by 3 -->
<ng-template #else_if_content1>
<span *ngIf="number_divide_by(3);else else_if_content2">
Show result of else_if_content1</span>
</ng-template>
<!-- Showing number divisible by 5 -->
<ng-template #else_if_content2>
<span *ngIf="number_divide_by(5);else else_if_content3">
Show result of else_if_content2</span>
</ng-template>
<!-- Showing rest of the number -->
<ng-template #else_if_content1>
<span>Show result of else_content</span>
</ng-template>
Hope this will resolve your effort.
Upvotes: 2