1

I am using Angular 9 for web development. I wanted to implement typeahead feature in my application. So I am using ng bootstrap typeahead. everything works perfectly as mentioned into below code.

search = (text$: Observable<string>) =>
    text$.pipe(
      debounceTime(150),
      distinctUntilChanged(),
      switchMap(term =>
        this.GameService.getCode(term).pipe(
          catchError(() => {
            return of([]);
          }))
      ),
    )

but somehow this is not working into the IE browser as it does not have support for arrow functions. To resolve this probem i have modified code in below manner:

search = function(text$: Observable<string>) {
    return text$.pipe(
      debounceTime(150),
      distinctUntilChanged(),
      switchMap(term => {
        let self = this;  // this is undefined and hence self is also undefined
        return self.GameService.getCode(term).pipe(
          map((res) => {
            this.isSearching = false;
            return res;
          }),
          catchError(() => {
            return of([]);
          }))
      }
      ),
    )
  }

how do i customize this code to support IE browser.

1 Answers1

2

Try defining let self = this before entering the function.

When using a function expression you you lose the scope of your code and your access to this - so you want to save your this before you enter your first function.

ZimGil
  • 877
  • 4
  • 12