Created
April 10, 2018 15:41
-
-
Save dahfazz/51e4d6b3bf0b4f74dda6adb99783ed8b to your computer and use it in GitHub Desktop.
angular scroll directive
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Observable } from 'rxjs/Rx'; | |
import { Directive, Output, ElementRef, EventEmitter } from '@angular/core'; | |
@Directive({ | |
// tslint:disable-next-line:directive-selector | |
selector: '[demainScroll]' | |
}) | |
export class ScrollDirective { | |
private page = 0; | |
@Output() scroll = new EventEmitter(); | |
constructor( | |
private elm: ElementRef, | |
) { | |
Observable | |
.fromEvent(this.elm.nativeElement, 'scroll') | |
.subscribe((event: Event) => { | |
this.scroll.emit(event.target['scrollLeft']); | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment