【问题标题】:AngularJS - Hiding value based on null and empty arrayAngularJS - 基于空和空数组的隐藏值
【发布时间】:2014-08-27 08:56:46
【问题描述】:

我试图在值为 null 或空数组(在 Firebug 中显示为 [])时执行 ng-hide。

我可以通过以下方式执行 null:

ng-hide="myData.Address == null"

但是当我尝试时:

ng-hide="myData.Address == null || myData.Address == []"

该值仍然出现。

【问题讨论】:

    标签: angularjs angularjs-scope ng-show angular-ng-if ng-hide


    【解决方案1】:

    试试这个:

    ng-hide="myData.Address == null || myData.Address.length == 0"
    

    【讨论】:

      【解决方案2】:

      null 和 [] 都是 false,更短更简洁的方式

      ng-show="myData.Address"
      

      【讨论】:

      【解决方案3】:
      ng-hide="!myData.Address || !myData.Address.length"
      

      【讨论】:

        猜你喜欢
        • 2021-06-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-05-18
        • 1970-01-01
        • 2013-09-03
        • 2015-06-25
        • 1970-01-01
        相关资源
        最近更新 更多