C
C
centerBel2016-09-08 13:52:03
JavaScript
centerBel, 2016-09-08 13:52:03

How to correctly display search results (angular)?

I use a simple filter

<input ng-model="searchText"></label>
<ul>
<li ng-repeat="friend in friends | filter:searchText">
</ul>

How can I make it so that all results are displayed, and the filter works only when at least 3 characters are entered in the input field. If less than 3, then no filter would be applied.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander Manakov, 2016-09-08
@centerBel

write your own filter. Something like:

<input ng-model="searchText"></label>
<ul>
  <li ng-repeat="friend in friends | filter:mySearchFilter(searchText)">
</ul>

$scope.mySearchFilter = function(searchText) {
  return function(value) {
    return value.indexOf(searchText) !== -1;
  }
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question