以下演示的是在AngularJS的{{}}表達式中使用三目運算符,其實,在Javascript中,三目運算符的格式也與其一模一樣,包括簡寫。
<div ng-if="scope=='all'" class="outline-border">
結果:巡檢路線數量:
<strong>{{statistics.routesCount==undefined?0:statistics.routesCount}}</strong>
,覆蓋設備設施總數:
<strong>{{statistics.routeEqTotal==undefined?0:statistics.routeEqTotal}}</strong>
,巡檢整體覆蓋率:<strong>{{statistics.eqCoverRate==undefined?0:statistics.eqCoverRate}}%</strong>
,特種設備數量:
<strong>{{statistics.routeSpecialEqTotal==undefined?"無":statistics.routeSpecialEqTotal}}</strong>
,特種設備巡檢覆蓋率:
<strong>{{statistics.eqSpecialCoverRate==undefined?0:statistics.eqSpecialCoverRate}}%</strong>.
</div>
如果是字符串,需要使用引號。
簡寫
<div ng-if="scope=='all'" class="outline-border">
結果:巡檢路線數量:
<strong>{{statistics.routesCount?statistics.routesCount:"字符串需使用引號"}}</strong>
,覆蓋設備設施總數:
<strong>{{statistics.routeEqTotal?statistics.routeEqTotal:0}}</strong>
,巡檢整體覆蓋率:
<strong>{{statistics.eqCoverRate?statistics.eqCoverRate:0}}%</strong>
,特種設備數量:
<strong>{{statistics.routeSpecialEqTotal?statistics.routeSpecialEqTotal:0}}</strong>
,特種設備巡檢覆蓋率:
<strong>{{statistics.eqSpecialCoverRate?statistics.eqSpecialCoverRate:0}}%</strong>.
</div>