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
在 rxjs v6 中它只是fromEvent
:
fromEvent(window, 'scroll').subscribe(() => this.manageScrollEvent());
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.