javascript – Angular 6:类型’typeof Observable’上不存在属性’fromEvent’

我正在为angular 6应用程序创建粘性标头的粘性导航栏指令

这是我到目前为止:

import { Directive, Input, Renderer, ElementRef, OnInit } from '@angular/core';
import { Observable } from 'rxjs';
import { fromEvent } from 'rxjs';

@Directive({
    selector: '[ngStickyNav]'
})

export class StickyNavDirective implements OnInit {
    private offsetTop: number;
    private lastScroll: number = 0;
    private isSticky: boolean = false;
    @Input('stickyClass') stickyClass: string;

    constructor(private elementRef: ElementRef, private renderer: Renderer) {

    }

    ngOnInit(): void {
        this.offsetTop = this.elementRef.nativeElement.offsetTop;

        Observable.fromEvent(window, 'scroll').subscribe(() => this.manageScrollEvent());
    }
}

我收到以下错误:

Property ‘fromEvent’ does not exist on type ‘typeof Observable’.

我的代码出了什么问题?新手虽然

解决方法:

在rxjs v6中它只是来自事件:

fromEvent(window, 'scroll').subscribe(() => this.manageScrollEvent());
上一篇:javascript – RXJS如何将Observable转换为Observable


下一篇:javascript – 在rx中创建资源的副作用(反应式扩展)