1

i'm trying to use rxjs for input autocomplete purpose but i keeping getting these error TypeError: terms.debounceTime is not a function even i'm setting these import 'rxjs/operators/debounceTime';

the function where i call that is :

    search(terms: Observable<string>) {
     return terms.debounceTime(400) 
     .distinctUntilChanged() 
     .switchMap(term => this.getActivities(term));
 }
A. Nassim
  • 99
  • 1
  • 9
  • 1
    Possible duplicate of [I dont get rxjs 6 with angular 6 with interval, switchMap, and map](https://stackoverflow.com/questions/50200859/i-dont-get-rxjs-6-with-angular-6-with-interval-switchmap-and-map) – a better oliver Jul 23 '18 at 14:35

3 Answers3

7

these working for me :

search(terms: Observable<string>) {
    return terms.pipe(
      debounceTime(400),
      distinctUntilChanged(),
      switchMap(term => this.getActivities(term))
    );
  }

it is about to pipe all !

A. Nassim
  • 99
  • 1
  • 9
1

Try this.

import 'rxjs/add/operator/debounceTime';

or

import { debounceTime, map } from 'rxjs/operators';
Dheeraj Kumar
  • 3,917
  • 8
  • 43
  • 80
0

Try this below way's

  • import Subject

    import { Subject } from 'rxjs/Subject'

  • Declare it

    private subject = new Subject<string>()

  • Then use it as

    search(terms: Observable<string>) {
     return  this.subject.debounceTime(400).distinctUntilChanged() 
         .switchMap(term => this.getActivities(term));
    }
    
Ramesh Rajendran
  • 37,412
  • 45
  • 153
  • 234