This repository was archived by the owner on May 29, 2019. It is now read-only.
This repository was archived by the owner on May 29, 2019. It is now read-only.
feat(typeahead): adding/removing class when source is promise #321
Closed
Description
I think it would be nice to set a class to mark the beginning and the end of the async source pull
I am using this to show a spinner at the right end of the input.
This is my code
var getMatchesAsync = function(inputValue) {
var locals = {$viewValue: inputValue};
element.addClass('bs-searching');
$q.when(parserResult.source(scope, locals)).then(function(matches) {
//it might happen that several async queries were in progress if a user were typing fast
//but we are interested only in responses that correspond to the current view value
if (inputValue === modelCtrl.$viewValue) {
if (matches.length > 0) {
scope.activeIdx = 0;
scope.matches.length = 0;
//transform labels
for (var i = 0; i < matches.length; i++) {
locals[parserResult.itemName] = matches[i];
scope.matches.push({
label: parserResult.viewMapper(scope, locals),
model: matches[i]
});
}
scope.query = inputValue;
element.removeClass('bs-searching');
} else {
resetMatches();
}
}
}, resetMatches);
};
Metadata
Metadata
Assignees
Labels
No labels