I am using Angular7, NgBootstrap 4. I have a input field with Typeahead directive.
When I follow custom search function format as written in documentation, works fine. When I try to modify format, I get an error:
I get this error:
core.js:12584 ERROR TypeError: Cannot set property 'searching' of undefined
What I am doing wrong?
This is working:
search = (text$: Observable<string>) =>
text$.pipe(
debounceTime(300),
distinctUntilChanged(),
tap(() => this.searching = true),
switchMap(term =>
this.searchService.fetchData(term).pipe(
tap(() => this.searchFailed = false),
catchError(() => {
this.searchFailed = true;
return of([]);
}))
),
tap(() => this.searching = false)
);
this is not working:
search = function (text$: Observable<string>) {
return text$.pipe(
debounceTime(300),
distinctUntilChanged(),
tap(() => this.searching = true),
switchMap(term =>
this.searchService.fetchData(term).pipe(
tap(() => this.searchFailed = false),
catchError(() => {
this.searchFailed = true;
return of([]);
}))
),
tap(() => this.searching = false)
);
}