*ngSwitch
1. 用法
<div [ngSwitch]="num"> <div *ngSwitchCase="0"> 0</div> <div *ngSwitchCase="1"> 1</div> <div *ngSwitchDefault>默认的</div> </div>
上面的相当于js
switch(num){ case 0: return 0; case 1: return 0; default: return '默认的'; }
2. ngSwitchCase
如何写多个条件呢?
<div [ngSwitch]="num"> <div *ngSwitchCase="0"> 0</div> <div *ngSwitchCase="(num === 1 || num===4) ? num : ''" > 1或者4</div> <div *ngSwitchDefault>默认的</div> </div>
上面的相当于js
switch(num){ case 0: return 0; case 1: case 4: return '1或4'; default: return '默认的'; }
标签:case,return,default,默认,学习,switch,num,笔记,angular From: https://www.cnblogs.com/sameen/p/17006281.html