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