最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Angular 6 throttleTime doesnt exist in Rx Js - Stack Overflow

programmeradmin2浏览0评论

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 badges
Add a ment  | 

2 Answers 2

Reset to default 9

It 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'));
发布评论

评论列表(0)

  1. 暂无评论