0

I'm trying to use some simple operators on a EventEmitter (from a FormModel.valueChanges) but I don't know how it's suppose to be done.

The class EventEmitter extends from Subject
export declare class EventEmitter<T> extends Subject<T>
so I tried several things:

this.patientForm.valueChanges.debounceTime(400) this.patientForm.valueChanges.source.debounceTime(400) this.patientForm.valueChanges.asObservable().debounceTime(400) Observable.create(this.patientForm.valueChanges).debounceTime(400)

tried in the constructor and in ngOnInit
the source is always undefined and the operators don't exist in the class.

I have this import import {Observable} from 'rxjs'; could be something with that?

(what I'm trying to do is save the form state in a Redux store, but don't want to do it in every keystroke)

2 Answers2

2

As Günter stated, operators aren't by default included

To import the Observable class, just use the following. In this case, you will have all the operators within the Observable class:

import {Observable} from 'rxjs/Rx';

To only have the debounceTime operator, you could use this:

import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/debounceTime';

Then the right way to use the debounceTime operator is:

this.patientForm.valueChanges.debounceTime(400).subscribe((val) => {
  (...)
});

See this article for more details:

Thierry Templier
  • 198,364
  • 44
  • 396
  • 360
  • `import {Observable} from 'rxjs/Rx';` didn't work (I think the operators aren't added at that point), instead I used `import 'rxjs/Rx';`. Is that a bad idea? – Sebastián Gaviria Apr 10 '16 at 18:40
0

You need to import the operators

import 'rxjs/add/operator/debounceTime'

or all of them at once

import 'rxjs/Rx';
Günter Zöchbauer
  • 623,577
  • 216
  • 2,003
  • 1,567