Angularjs动态ng-if数据绑定在span中

Angularjs dynamic ng-if data binding in span

本文关键字:span 数据绑定 动态 ng-if Angularjs      更新时间:2023-09-26

我的视图中有一个Angular表达式:

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

因此,如果我在StoreList中有任何项目,那么我将显示计数,否则我只显示0个产品。

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

我该如何解决这个问题?

尝试使用:

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

这不是正确格式化的

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

应该是

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