How to do a search in a list of Ionic Framework Angularjs

0

I have an ionic application, however I need to do a search or filter on the contacts that appear on the screen but I can not and the worst that does not return any errors:

My control:

.controller('ContatosCtrl', function($scope, $timeout, $http) {
      $scope.limite = 10;
      $scope.contatos = [];
      $scope.loadMore = function() {
        $timeout(function(){
        $http.get('js/dados.json').then(function(response) {
          angular.forEach(response.data, function(items) {
            $scope.total = items.length;
            for (i=0; i < $scope.limite; i++) {
              $scope.contatos.push(items[i]);
            }
            $scope.$broadcast('scroll.infiniteScrollComplete');
          });
        }, function(err) {
            console.error('ERR', err);
        });
        $scope.limite +=10;
        }, 200);
      };
    })

And this is my template:

    <ion-view view-title="Contatos">
    <ion-header-bar class="bar bar-subheader item-input-inset bar-busca bar-positive">
        <div class="item-input-wrapper">
          <i class="icon ion-search placeholder-icon"></i>
          <input type="search" min-length="1" placeholder="Buscar" ng-model="busca.search">
          <i class="icon ion-android-close placeholder-icon" ng-if="busca.search" ng-click="clearSearch()"></i>
        </div>
    </ion-header-bar>
      <ion-content>
        <ion-list>
          <ion-item class="item-remove-animate item-avatar item-icon-right" ng-repeat="contato in contatos track by contato.codigo | filter:busca.search" type="item-text-wrap" href="#/tab/contatos/{{contato.codigo}}">
            <img ng-src="{{contato.face}}">
            <h2>{{contato.nome}}</h2>
            <p>{{contato.telefone}}</p>
            <i class="icon ion-chevron-right icon-accessory"></i>
          </ion-item>
        </ion-list>
        <ion-infinite-scroll ng-if="!moredata" on-infinite="loadMore()" distance="10%"></ion-infinite-scroll>
      </ion-content>
    </ion-view>

I need to do a simple search filter, I'm not sure if just adding filter would already work the search.

    
asked by anonymous 08.06.2015 / 17:07

1 answer

1

You just need to change the way you use the filter along with "track by".

ng-repeat="contato in contatos | filter:busca.search track by contato.codigo"
    
16.06.2015 / 04:54