如果使用AngularJS在HTML标记上使用/ else

时间:2015-05-21 16:14:45

标签: javascript html angularjs

<span ng-if="ItemIndex.ItemCount>0"><a href="#" ng-click="deleteItem(ItemIndex)"
    class="underlined-text-button"><i
    class="glyphicon glyphicon-remove"></i> Remove items</a>
</span>

如果我的项目超过0,则会收到“删除项目”的文字。但我想,如果我有一个项目,文本更改为“删除项目” 所以,

item == 1 ==删除项目

item&gt; 1 ==删除项目

我该如何设置?

1 个答案:

答案 0 :(得分:1)

像这样使用,

<span ng-if="ItemIndex.ItemCount>0">
    <a href="#" ng-click="deleteItem(ItemIndex)"
    class="underlined-text-button"><i
    class="glyphicon glyphicon-remove"></i> 

    {{ (ItemIndex.ItemCount == 1) ? 'Remove item' : 'Remove items' }}


    </a>
</span>

如果(ItemIndex.ItemCount == 1)为真,则打印Remove item,否则打印Remove items

您可以使用ng-showng-hideng-if

 <span ng-if="ItemIndex.ItemCount>0">
    <a href="#" ng-click="deleteItem(ItemIndex)"
    class="underlined-text-button"><i
    class="glyphicon glyphicon-remove"></i> 


    <span ng-show="ItemIndex.ItemCount == 1"> Remove item </span>
    <span ng-show="ItemIndex.ItemCount > 1"> Remove items </span>

    </a>
</span>