Lubudubu1010
Lubudubu1010

Reputation: 199

Angularjs search from string start

is there any way to compare strings starting from first char (not comparing chars inside a existing string.

example: I have array with "Boobo", "Frodo", "Ookami" "Waki", "Konsta", "Perrys", "Ami". And when i have default search filter, after typing "O" in input i will get Boobo, Frodo, Ookami, Konsta because they have "o" letter inside. What i want is to get only Ookami, because this name starts with "o", after typing. Strict comparison isn`t a solution, because i would have to type whole name to get it showed.

Upvotes: 1

Views: 1016

Answers (1)

Chris Charles
Chris Charles

Reputation: 4446

You can use a custom filter: startswith angular filter

This allows you to say:

<li ng-repeat="thing in things | startsWith: search">{{thing}}</li> 

instead of

<li ng-repeat="thing in things | filter: search">{{thing}}</li> 

Upvotes: 1

Related Questions