Search code examples
angularjsangular-ui-typeahead

How to truncate the length of a result in AngularJS uib-typeahead


I'm using the Angular UI Bootstrap typeahead as follows:

<input type="text" ng-model="selectedUser"
    uib-typeahead="user as user.Name for user in allUsers | filter:$viewValue | limitTo:8"/>

I'm looking to truncate the values of long results so that the dropdown doesn't overflow. In other text controls I can use | trimValue:20, but that doesn't seem to be implemented in the typeahead.


Solution

  • What works:

    <input type="text" ng-model="selectedUser"
        uib-typeahead="user as user.Name | trimValue:20 for user in allUsers | filter:$viewValue | limitTo:8"/>
    

    What doesn't work:

    <input type="text" ng-model="selectedUser"
        uib-typeahead="user as user.Name for user in allUsers | filter:$viewValue | limitTo:8 | trimValue:20"/>