Reputation: 5566
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
Upvotes: 4
Views: 5192
Reputation: 4039
In rxjs v6 it is just fromEvent
:
fromEvent(window, 'scroll').subscribe(() => this.manageScrollEvent());
Upvotes: 11