在主题angular2错误上使用throttleTime函数

时间:2017-08-01 01:11:15

标签: angular rxjs reactive-programming

我正在尝试对某个主题使用throttleTime运算符。我已导入运营商。我收到此错误:this.cropSubject.asObservable(...).throttleTime is not a function。我无法弄清楚出了什么问题。这是一个错误吗?

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 个答案:

答案 0 :(得分:1)

您想要添加运算符。您只是导入实施。

import 'rxjs/add/operator/throttleTime';

它会将throttleTime运算符添加到原型中。