2017-08-01 50 views
3

我試圖在主題上使用throttleTime操作符。我輸入了操作員。我收到這個錯誤:this.cropSubject.asObservable(...).throttleTime is not a function。我無法弄清楚發生了什麼問題。這是一個錯誤?使用throttleTime函數關於主題angular2錯誤

import { Observable } from 'rxjs/Observable'; 
import { Subject } from 'rxjs/Subject'; 
import { throttleTime } from 'rxjs/operator/throttleTime'; 


export class EditItemComponent implements OnInit, AfterViewInit{ 


    cropSubject: Subject<string> = new Subject<string>(); 


    constructor(private taggingDataService: TaggingDataService, private _elementRef : ElementRef) { 
    taggingDataService.selectedTags.subscribe((newTags) => { 
     this.selectedTags = newTags; 
    }) 
    this.cropSubject.asObservable().throttleTime(1000).subscribe((croppedImageSrc) => { 
     this.updateImageData(croppedImageSrc); 
    }) 
} 

回答

1

您想要添加運算符。你只是導入實現。

import 'rxjs/add/operator/throttleTime'; 

它會將throttleTime運算符添加到原型。

+0

aahh ....這總是讓我。我正在從'rxjs/operator/throttleTime'執行'import {throttleTime};' – quantdaddy

+0

是的......這只是實現......您可以使用它,但它很奇怪:'throttleTime.call(someObservable,time)' –

+1

如果如果讓你感覺更好,我正在努力打造一個大公關,讓你和其他人在不久的將來更容易。 (我希望)。 :D –