I am using angular/cli": "~6.1.5
and rxjs": "^6.0.0
As i new to Angular 6 i started learning from official document
.js~Observable.html
code is below
var clicks = Rx.Observable.fromEvent(document, 'click');
var result = clicks.throttleTime(1000);
result.subscribe(x => console.log(x));
Same above code i tried in angular 6
fromEvent(mybuttonId, 'click')
.subscribe((event) => console.log('clicked'));
But if i add .throttleTime(1000) to from event then it will throw error
Property 'throttleTime' does not exist on type 'Observable
'`.
if i try to add Observable.fromEvent then that method doesn't exist
I have imported Rx js as
import {Observable, fromEvent, from, of} from 'rxjs';
import {throttleTime} from 'rxjs/operators';
Can any one help me where i can find exact document for latest version.
Thanks
I am using angular/cli": "~6.1.5
and rxjs": "^6.0.0
As i new to Angular 6 i started learning from official document
http://reactivex.io/rxjs/class/es6/Observable.js~Observable.html
code is below
var clicks = Rx.Observable.fromEvent(document, 'click');
var result = clicks.throttleTime(1000);
result.subscribe(x => console.log(x));
Same above code i tried in angular 6
fromEvent(mybuttonId, 'click')
.subscribe((event) => console.log('clicked'));
But if i add .throttleTime(1000) to from event then it will throw error
Property 'throttleTime' does not exist on type 'Observable
'`.
if i try to add Observable.fromEvent then that method doesn't exist
I have imported Rx js as
import {Observable, fromEvent, from, of} from 'rxjs';
import {throttleTime} from 'rxjs/operators';
Can any one help me where i can find exact document for latest version.
Thanks
Share Improve this question asked Sep 2, 2018 at 12:36 scottscott 3,19219 gold badges58 silver badges90 bronze badges2 Answers
Reset to default 9It can be piped on to an Observable like this:
import { fromEvent } from 'rxjs';
import { throttleTime } from 'rxjs/operators';
subscription = fromEvent(document, 'click')
.pipe(throttleTime(1000))
.subscribe(x => console.log(x));
You can find it in the Official Docs here:
fromEvent | throttleTime
Also make sure to unsubscribe
from the subscription
to avoid any memory leaks. Generally, this is done in ngOnDestroy
Thanks to Siddharth Ajmera for the clue for using pipe. In latest Version of rx js we can do as below
fromEvent(this.hoverSection, 'click')
.pipe(throttleTime(1000))
.subscribe((event) => console.log('clicked'));