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>


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM