使用 AngularJS 的 filter 搜尋陣列中的物件

  • 248
  • 0

A simple example shows

How to search objects in an array by AngularJS filter

JS

var app = angular.module('myApp', []);
app.controller('myController', ['$scope','$filter', function($scope,$filter){
  $scope.objArray = [
    {id:1,name:'A'},
    {id:2,name:'B'}
  ];
}]);

HTML

<body ng-app="myApp">
    <div ng-controller="myController">
        <input type="text" ng-model="searchId">
        <p>{{ (objArray | filter:{id:searchId}) }}</p>
    <div>
</body>