kishore babu
kishore babu

Reputation: 1

angular typahead fetch results with starting letter only

JS Code below :

$scope.startsWith = function(state, viewValue) { return state.substr(0, viewValue.length).toLowerCase() == viewValue.toLowerCase(); }

html< start tag< input name="states" id="states" type="text" placeholder="Search Countries..." ng-model="selected" typeahead="state.COUNTRY_CODE as state.COUNTRY_DESC for state in states | filter:$viewValue:statestartsWith | limitTo:8">

This is still not searching for first letter, it is giving results matching in middle of the string also. Please help

Upvotes: 0

Views: 253

Answers (1)

aurelien974
aurelien974

Reputation: 71

The order of filters are incorrect.

typeahead="state.COUNTRY_CODE as state.COUNTRY_DESC for state in states | startsWith:$viewValue | limitTo:8"

In order to make it work, you have to define the function startsWith as a filter in your angular app. See this angular documentation

Also your parameter name is state but the typeahead will return the country code of the state so be careful with your variable names.

Upvotes: 0

Related Questions