【问题标题】:Angularjs dynamic ng-if data binding in span跨度中的Angularjs动态ng-if数据绑定
【发布时间】:2015-11-30 18:37:10
【问题描述】:

我认为有这个 Angular 表达式:

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

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

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

我该如何解决这个问题?

【问题讨论】:

    标签: javascript angularjs angularjs-directive angularjs-scope


    【解决方案1】:

    尝试:

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

    【讨论】:

      【解决方案2】:

      格式不正确

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

      应该是

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

      【讨论】:

        猜你喜欢
        • 2016-10-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-14
        • 1970-01-01
        • 2014-07-27
        相关资源
        最近更新 更多