Angular JS具有单个ng模型/输入的多重过滤器

时间:2014-09-02 05:36:20

标签: angularjs angularjs-ng-repeat

如何使单个搜索过滤多个对象值?

例如:如果我搜索' 1'或者一个'然后结果应该来........

到目前为止我已经尝试过了:

HTML:

    <input type="text" ng-model="model_search">
    <ul>
      <li ng-repeat="obj_data in data | filter:{id:model_search, text:model_search}">{{obj_data.id}}-->{{obj_data.text}}</li>
    </ul>

JS:

var myApp = angular.module('myApp', []);

myApp.controller('MyCtrl', function($scope) {
  $scope.data = [{
    "id": 1,
    "text": 'one'
  }, {
    "id": 2,
    "text": 'two'
  }, {
    "id": 3,
    "text": 'three'
  }, {
    "id": 4,
    "text": 'four'
  }, {
    "id": 5,
    "text": 'five'
  }];

});

DEMO PLUNKR

1 个答案:

答案 0 :(得分:2)

你很接近,只需将过滤器更改为:

 <li ng-repeat="obj_data in data | filter:model_search">{{obj_data.id}}-->{{obj_data.text}}</li>

下面的工作plunkr http://plnkr.co/edit/0jeA0u8oaz16cYnsZjfw?p=preview