component.html
<div (scroll)="onScroll($event)">
//Content
</div>
Now i just used the $event.target properties scrollTopMax and scrollTop:
component.ts
onScroll(event: any): void {
let elementHeight = event.target.scrollTopMax;
let scrollPosition = event.target.scrollTop;
if( elementHeight - scrollPosition < 100) {
//add Content
}
}
Of course you will need some function checking if new content is already rendered.
If not the onScroll() function will be called much too often.
In my case i insert other component with *ngFor and created and @Output to notify the parent about a finished rendering.
child.component.ts
@Output()
rendered = new EventEmitter();
ngAfterViewChecked() {
this.rendered.emit(<uniqueIdentifier>);
}
component.html
<div (scroll)="onScroll($event)">
<child *ngFor="element in displayedElement"
(rendered)="elementRendered($event)">
</child>
component.ts
elements: any;
displayedElements: any[];
renderedElements: new Set();
addElements(): void {
/////
}
elementRendered(<uniqueIdentifier>: any) {
this.renderedElements.add(<uniqueIdentifier>);
}
onScroll(event: any): void {
if( this.displayedElements.length == this.renderedElements.size) {
let elementHeight = event.target.scrollTopMax;
let scrollPosition = event.target.scrollTop;
if( elementHeight - scrollPosition < 100) {
this.addElements();
}
}
}
(scroll)="update($event)"on the element in your template you want to get scroll notifications should do what you want, no?