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
In rxjs v6 it is just fromEvent
:
fromEvent(window, 'scroll').subscribe(() => this.manageScrollEvent());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With