I'm using ng-select custom server-side search to load data, whether the user provided a search term or not.
component.html
<ng-select [items]="filterValues$ | async"
[typeahead]="filterValuesInput$"
[multiple]="true"
(open)="getFilterValues(pref.id)"
[loading]="filterValuesLoading"
bindLabel="name"
[(ngModel)]="filter_values">
</ng-select>
component.ts
getFilterValues(filterName) {
this.filterValues$ = concat(
of([]), // default items
this.filterValuesInput$.pipe(
startWith([]),
distinctUntilChanged(),
tap(() => this.filterValuesLoading = true),
switchMap(term => this.preferencesService.getFilterValues(filterName, '' + term).pipe(
map(res => res.filter_values),
catchError(() => of([])), // empty list on error
tap(() => this.filterValuesLoading = false)
))
)
);
}
The problem I noticed is that whenever I open the select dropdown, it triggers a console error:
Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'loading: false'. Current value: 'loading: true'.
After that the loading spinner triggered by this.filterValuesLoading works fine if a search term is provided. What is the problem here? Thanks!