在AngularJS中按ng-repeat过滤键

时间:2016-04-15 02:52:12

标签: angularjs angularjs-ng-repeat ng-repeat

我循环浏览一些像这样的对象:

<div ng-repeat="choiceID in inputs[field.$id]">
    <span ng-repeat="(key, choice) in submission.savedChoices | filter:{key:choiceID}">
        {{key}}
        {{choice}}
    </span>
</div>

正如您所看到的那样,我尝试使用(key, value)对中的密钥进行过滤,但它会引发语法错误,这样做的正确方法是什么?

1 个答案:

答案 0 :(得分:0)

尝试使用ng-if:

    <div ng-repeat="choiceID in inputs[field.$id]">
      <span ng-repeat="(key, choice) in submission.savedChoices" ng-if="key==choiceID">
          {{key}}
          {{choice}}
      </span>
    </div>