Skip to content

Instantly share code, notes, and snippets.

@dahfazz
Created April 10, 2018 15:41
Show Gist options
  • Save dahfazz/51e4d6b3bf0b4f74dda6adb99783ed8b to your computer and use it in GitHub Desktop.
Save dahfazz/51e4d6b3bf0b4f74dda6adb99783ed8b to your computer and use it in GitHub Desktop.
angular scroll directive
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