Angular 2模板 - if elseif else

时间:2018-01-19 08:43:06

标签: angular

有没有办法在Angular 2模板中使用if elseif else结构?

这是if else示例:

[text]="company ? company.name : 'Select a company'"

我需要添加elseif

1 个答案:

答案 0 :(得分:2)

Angular还没有 if elseif else 行为,但你可以达到如下相同的行为



<!-- 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>
&#13;
&#13;
&#13;

希望这会解决你的努力。