A. Nassim
A. Nassim

Reputation: 99

TypeError: debounceTime is not a function

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));
 }

Upvotes: 1

Views: 4323

Answers (3)

A. Nassim
A. Nassim

Reputation: 99

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 !

Upvotes: 7

Ramesh Rajendran
Ramesh Rajendran

Reputation: 38673

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));
    }
    

Upvotes: 0

Dheeraj Kumar
Dheeraj Kumar

Reputation: 4175

Try this.

import 'rxjs/add/operator/debounceTime';

or

import { debounceTime, map } from 'rxjs/operators';

Upvotes: 2

Related Questions