我有以下代码的伟大工程:在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如果没有内插,它仍然不起作用。感谢您的建议。 –