Answer the question
In order to leave comments, you need to log in
How to abort a request?
I use ng-select, following the example from the docs ( Demo, bottom example ), I did a search through the backend:
private loadCountry() {
this.countryList$ = concat(
of([]), // default items
this.countryInput$.pipe(
debounceTime(this.debounceTime),
distinctUntilChanged(),
tap(() => this.countryLoading = true),
switchMap(search => {
return this.locationService.getCountry(search).pipe(
catchError(() => of([])), // empty list on error
tap(() => this.countryLoading = false)
).toPromise().then(data => {
const countries = [];
const cnt = data.body.length;
for (let i = 0; i < cnt; i++) {
countries.push(new Country(data.body[i]));
}
return countries;
});
}),
)
);
}
private loadCountry() {
this.countryList$ = concat(
of([]), // default items
this.countryInput$.pipe(
debounceTime(this.debounceTime),
distinctUntilChanged(),
tap(() => this.countryLoading = true),
switchMap(search => {
if (!search) {this.countryLoading = false; return []; } // Мое решение
return this.locationService.getCountry(search).pipe(
catchError(() => of([])), // empty list on error
tap(() => this.countryLoading = false)
).toPromise().then(data => {
const countries = [];
const cnt = data.body.length;
for (let i = 0; i < cnt; i++) {
countries.push(new Country(data.body[i]));
}
return countries;
});
}),
)
);
}
Answer the question
In order to leave comments, you need to log in
In the pipe, use the filter rxjs operator and filter out null values.
https://www.learnrxjs.io/operators/filtering/filte...
And in the example, the input parameter [minTermLength]="2"
does not tell you anything?
and remove the promise, it's a nightmare
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question