AngularJS的三目运算符

以下演示的是在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>

posted on 2017-10-18 20:00  Yoooshiki  阅读(1814)  评论(0编辑  收藏  举报

导航