过滤器和AngularJS问题

时间:2015-10-21 12:05:27

标签: angularjs

我使用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>

Contacts array http://zupimages.net/up/15/43/52mu.png

0 个答案:

没有答案