javascript - ng-如果 Angular 不起作用

标签 javascript angularjs angular-ng-if

我的问题是 ng-if 的行为并不像我假装的那样,我有一个带有 _name 属性的对象数组,我做了一个 ng-repeat ,在里面我想区分一些以特定方式命名的对象和其他的。基于我正在制作我的 ng-if,但是打印了两次行,并且它的内容应该是其中之一,任何人都可以指出我失败的地方吗?谢了

在 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>

最佳答案

你的第二个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相反,但您的代码不会短得多。

关于javascript - ng-如果 Angular 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26786616/

相关文章:

javascript - 在不打开新页面的情况下从浏览器调用客户端 URL

Javascript 随机 YouTube 视频自动播放

javascript - 使用 ng-grid 仅选择特定列

javascript - 如何为 AngularJS 应用程序定义两种模式(夜间/白天)

javascript - 具有多个参数的 Angular ng-if =""

javascript - casperjs点击标签

javascript - IE11 : empty http request header not being passed

angularjs - 在最后一个 md-tab 之后删除

html - Angular ng-if 更改跨度文本

javascript - 如何使用 Angular *ngIf 监听 400(错误请求)?