Created
June 10, 2019 06:40
-
-
Save NetanelBasal/bb7a9320d6d356fb4ea81709224256b4 to your computer and use it in GitHub Desktop.
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
@Component({ | |
selector: 'infinite-scroll', | |
template: `<ng-content></ng-content><div #anchor></div>` | |
}) | |
export class InfiniteScrollComponent implements OnInit, OnDestroy { | |
... | |
ngOnInit() { | |
const options = { | |
root: this.isHostScrollable() ? this.host.nativeElement : null, | |
...this.options | |
}; | |
this.observer = new IntersectionObserver(([entry]) => { | |
entry.isIntersecting && this.scrolled.emit(); | |
}, options); | |
this.observer.observe(this.anchor.nativeElement); | |
} | |
private isHostScrollable() { | |
const style = window.getComputedStyle(this.element); | |
return style.getPropertyValue('overflow') === 'auto' || | |
style.getPropertyValue('overflow-y') === 'scroll'; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment