AngularJS不必要的跨度

时间:2015-08-27 07:12:43

标签: html angularjs

我有以下HTML / AngularJS代码:

<span ng-show="true" ng-repeat="timeRangeObject in timeRangeObjects" ng-if="ifExpression">
    <span class="progress-bar progress-bar-{{timeRangeObject.type}}" style="width: {{timeRangeObject.percentage}}%" />
</span>

此代码的结果是:

<span>
    <span class="progress-bar ...
</span>
<span>
    <span class="progress-bar ...
</span>
<span>
    <span class="progress-bar ...
</span>
<span>
    <span class="progress-bar ...
</span>

但我绝对需要这个:

<span>
    <span class="progr ...
    <span class="progr ...
    <span class="progr ...
    <span class="progr ...
</span>

有可能这样做吗?

非常感谢!

1 个答案:

答案 0 :(得分:4)

ng-repeat放到内跨区域。我删除了ng-show=true部分,这是不必要的。

<span ng-if="ifExpression">
    <span ng-repeat="timeRangeObject in timeRangeObjects" class="progress-bar progress-bar-{{timeRangeObject.type}}" style="width: {{timeRangeObject.percentage}}%" />
</span>