Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 6 : Property 'fromEvent' does not exist on type 'typeof Observable'

I am creating sticky navbar directive for sticky header in my angular 6 app

Here is what I have so far:

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());
    }
}

I am getting the following error :

Property 'fromEvent' does not exist on type 'typeof Observable'.

what is wrong with my code? newbie though

like image 362
The Dead Man Avatar asked Dec 17 '22 21:12

The Dead Man


1 Answers

In rxjs v6 it is just fromEvent:

fromEvent(window, 'scroll').subscribe(() => this.manageScrollEvent());
like image 117
PeS Avatar answered Dec 28 '22 10:12

PeS