-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
I am experiencing the following issue:
-
I setup the control in the following way. Async call is done to an API, which hits an external resource. This operation takes, at least, 1 second.
<input class="form-control"
name="searchForm"
required
#searchForm="ngModel"
[(ngModel)]="searchModel"
[typeahead]="searchResults"
(typeaheadOnSelect)="selectFromSearchResult($event)"
typeaheadOptionField="fullName"
typeaheadWaitMs="200"
(keypress)="loading=true"
size="30" type="text" />
Component code is as follows:
this.searchResults = Observable.create((observer:any) => {
this.loading = true;
this.contactsService.search(this.searchModel)
.subscribe((result: any) => {
this.loading = false;
observer.next(JSON.parse(result._body));
})
});
- Upon typing, after 200ms a request is executed.
- I hit tab before the response comes back, so focus is now in another control.
- After the results come back from the server, typeahead control obtains focus again. This is not an expected behaviour.
Q: is there a way to cancel the request?
Q: shouldn't the control cancel the request on focus lost?
Thank you in advance!