var myApp = angular.module('myApp', []);
myApp.controller('oneCtrl', function($scope) {
$scope.cast = [
{
name: 'Jerry',
character: 'strong, kindful man'
},
{
name: 'Jack',
character: 'strong man'
},
{
name: 'Kate',
character: 'a little girl'
},
{
name: 'Lucy',
character: 'a kindful girl'
}
];
});
<div ng-app="myApp">
<div ng-controller="oneCtrl">
<h4>对name进行过滤</h4>
<input type="text" ng-model="search.name">
<table>
<tr ng-repeat="actor in cast | filter:search">
<td>{{ actor.name }}</td>
<td>{{ actor.character }}</td>
</tr>
</table>
<hr>
<h4>对name和character进行过滤(两者中一个符合就行)</h4>
<input type="text" ng-model="search1">
<table>
<tr ng-repeat="actor in cast | filter:search1">
<td>{{ actor.name }}</td>
<td>{{ actor.character }}</td>
</tr>
</table>
</div>
</div>
tr:nth-child(odd) {
background-color: #ddd;
}
tr:nth-child(even) {
background-color: #fff;
}
table {
border-collapse: collapse;
font-family: arial;
}
td {
padding: 4px 8px;
border: 1px solid #999;
}
h4 {
padding: 4px 8px;
font-family: 'microsoft yahei', 'Ubuntu';
font-size: 18px;
}