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)

1

2 Answers 2

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:

Sign up to request clarification or add additional context in comments.

1 Comment

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?
0

You need to import the operators

import 'rxjs/add/operator/debounceTime'

or all of them at once

import 'rxjs/Rx';

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.