ng-if angular not not working

时间:2014-11-06 18:21:08

标签: javascript angularjs angular-ng-if

我的问题是ng-if的行为并不像我假装的那样,我有一个带有_name属性的对象数组,我正在制作一个ng-repeat和内部,我想要辨别一些以特定方式命名的对象和其他。基于我制作我的ng-if,但是打印两次行和它的内容应该是一个或另一个,任何人都可以指出我失败的地方? TKS

在clusterEntity.cluster中的数组下面;

       locations:{
          location:[
            {_name: "staging", _path: ""},
            {_name: "temp", _path: ""},
            {_name: "working", _path: ""}
          ]
        },

<div ng-repeat="location in clusterEntity.cluster.locations.location">

    <div ng-if="
                location._name === 'staging' || 
                location._name === 'working' || 
                location._name === 'temp'">
      <something here>
    </div>


    <div ng-if="
                location._name !== 'staging' || 
                location._name !== 'working' || 
                location._name !== 'temp'">

      <something there>
    </div>
  </div>

1 个答案:

答案 0 :(得分:3)

您的第二个ng-if应使用逻辑AND,而不是OR:

<div class="row" ng-if="location._name !== 'staging' && location._name !== 'working' && location._name !== 'temp'">

与:

相同
<div class="row" ng-if="!(location._name === 'staging' || location._name === 'working' || location._name === 'temp')">

您可以使用ng-switch代替,但您的代码不会更短。