我使用AngularJS的$filter('filter')
时出现问题。当我在行中有一个空单元格时似乎无法正常工作......
当一个单元格在一行上为空时如果我添加一个过滤器就可以了,但是当删除过滤器时,从contacts
删除带有空单元格的行...
AngularJS脚本:
app.controller("ContactNgController", function($scope, $http, $filter, $document) {
$http.get('/api/mes-contacts').success(function(data, status, headers, config) {
$scope.contacts = data.contacts;
$scope.filteredContacts = data.contacts;
$scope.nbContacts = data.contacts.length;
$scope.limit = data.limit;
$scope.onChange = function(){
$scope.contacts = data.contacts;
$scope.filteredContacts = $filter('filter')($scope.contacts, $scope.search);
};
});
});
表格HTML:
<table class="table table-striped table-hover table-bordered">
<thead>
<tr>
<th>Prénom<input type="text" ng-model="search.firstname" placeholder="Recherche par prénom" ng-change="onChange()" autocomplete="off"></th>
<th>Nom<input type="text" ng-model="search.lastname" placeholder="Recherche par nom" ng-change="onChange()" autocomplete="off"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="contact in contacts | filter:search | limitTo:limit">
<td>{{contact.firstname}}</td>
<td>{{contact.lastname}}</td>
</tr>
</tbody>
</table>