Angularjs动态ng-if数据绑定跨度

问题描述 投票:0回答:2

我认为该Angular表达式:

 <span ng-if="{{list.StoreList ? (list.StoreList.length ' Products)' : '(0 Products)'}}"> </span>

因此,如果我在StoreList中有任何商品,那么我将显示计数,否则,我将仅显示0件商品。

我收到来自Angularjs的意外错误。

我该如何解决?

javascript angularjs angularjs-directive angularjs-scope
2个回答
0
投票

尝试使用:

<span ng-if="list.StoreList">{{'(' + list.StoreList.length + ' Products)'}}</span>
<span ng-if="!list.StoreList">(0 Products)</span>

0
投票

此格式格式不正确

<span ng-if="{{list.StoreList ? (list.StoreList.length ' Products)' : '(0 Products)'}}"> </span>

应该是

<span ng-if="{{ list.StoreList ? '(' + list.StoreList.length + ' Products)' : '(0 Products)'}}"> </span>
© www.soinside.com 2019 - 2024. All rights reserved.