[typeahead][bug] filters not being applied on promises #993
Description
I was originally going to comment on Stack Overflow, but I figured this is the more appropriate place to discuss this.
Reference to response I am commenting on:
http://stackoverflow.com/a/15930592/1217025
So I tried to add filters on the plunkr example @pkozlowski-opensource provided in his SO response, but the filters didn't seem to ever get applied.
e.g.
<input ... typeahead="suggestion for suggestion in cities($viewValue) | limitTo:4">
I tried digging into the ui-bootstrap typeahead core, and I feel like it comes down to the function var getMatchesAsync = function(inputValue) {...}
.
In that function it calls:
$q.when(parserResult.source(scope, locals)).then(function(matches) {
...
}, ...);
It seems like parserResult.source(scope, locals)
executes the part of the sourceArray
expression that includes the sourceArray and everything to the right of it (really just filters). So in the example earlier, it executes cities($viewValue) | limitTo:4
. Since cities($viewValue)
returns a promise object, the limitTo
filter does get run, but it simply returns the promise object unchanged since it doesn't know how to handle objects. Once the passed back promise object is resolved, the success callback in .then(function(matches) {...}, ...);
fires, but all the filter information is essentially lost.
To sum up, it seems like the issue is that all filters get applied to the promise object, which typically yields no change, and does not get applied to the result of the promise.