Search code examples
javascriptangularjsangular-filters

How to set minimum number of charcter to search in angular js filter?


I am doing angular js filter .

Here I am searching customer name .

Everything is working fine ,but I want to modify it a bit .

Here after typing 2 character ,my search is working .

But my requirement is to start search immediately after typing the first character . I have tried some code but its not working .

 <tr class="gradeU" ng-repeat="x in invoice| filter:invoice_name | filter:customer_name:strLimit: 1">    

Here I am using strLimit to do it.

But its not working at all.

I have attached a snap ,please have a look.

enter image description here

Any idea ?

Thank you


Solution

  • Works fine for me here ! Can you see anything missing from snippet and your original code #?

    You don't even need the strLimit:1 to achieve this.

    var app = angular.module('app',[]);
    app.controller('Ctrl',function($scope){
      
      $scope.invoice = [{"id":123,"name":"Shrada"},
                        {"id":111,"name":"Vikram"},
                        {"id":342,"name":"Shrada"},
                        {"id":231,"name":"Melina"}
      
      ];
      
      });
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
    
    <div ng-app="app" ng-controller="Ctrl">
      
      <input type="text" ng-model="invoice_name"/>
      <input type="text" ng-model="customer_name"/>
    <div class="gradeU" ng-repeat="x in invoice| filter:invoice_name | filter:customer_name">    
      {{x.id}} - {{x.name}}
      </div>
      </div>