使用角度js匹配两个数组

时间:2015-04-28 08:12:34

标签: javascript angularjs ionic-framework

我有两个数组。我想使用ng_if和其他条件匹配数组的值,如下所示:

var a = {'nishant','karan','jyotsna'};
var b = {'nishant','prbh','moh'};
    <div ng-repeat="x in a">
      <div ng-if="x!=b">
         {{x}}
      </div>
      <div ng-else>
        <div ng-repeat="x in b">
            {{x}}
        </div>
      </div>
    </div>

1 个答案:

答案 0 :(得分:0)

我认为ngElse不是内置指令,但您可以使用其他ngIf

http://plnkr.co/edit/HB7zK0Q8nGFRkj44U1AR?p=preview

<div ng-repeat="x in a">
  <div ng-if="b.indexOf(x) !== -1">
     {{x}} is in b
  </div>
  <div ng-if="b.indexOf(x) === -1">
    {{x}} is not in b:
    <div ng-repeat="x in b">
        b: {{x}}
    </div>
  </div>
  <hr/>
</div>