我有以下代碼的偉大工程:在HTML設置角變量,同時使用NG-重複
<div class="progress progress-striped active">
<div class="progress-bar progress-bar-success" style="width: {{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}%;background-color: #5cb85c">
{{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}
</div>
</div>
然而,正如你所看到的,我是在重複{{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}
了很多,所以我想將其分配到角度變量。我還想對結果進行NG切換。這是我已經嘗試過
<div class="progress progress-striped active" ng-init = "barPercentage= {{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}">
<div ng-switch="barPercentage">
<div ng-switch-when=">=0" class="progress-bar progress-bar-success" style="width: {{barPercentage}}%;background-color: #5cb85c">
{{(p.availableIpAddressCount/p.totalIpAddressCount)*100|number:0}}
</div>
</div>
</div>
但是,這根本不起作用,但我不確定爲什麼。我在控制檯中沒有錯誤。
任何想法?
怎麼樣只是用NG-如果 – MMK
你不需要插即'NG-的init =「barPercentage =(p.availableIpAddressCount/p.totalIpAddressCount)* 100 |編號:0 「' – Satpal
@Satpal如果沒有內插,它仍然不起作用。感謝您的建議。 –