npm install --save ng-infinitescroll
Add InfiniteScrollModule
to your list of module imports:
import {InfiniteScrollModule} from 'ng-infinitescroll';
@NgModule({
imports: [
...
InfiniteScrollModule
],
...
})
export class AppModule { }
Create an array(list) in your component:
import { Component } from '@angular/core';
@Component({
...
templateUrl: './app.component.html',
})
export class AppComponent {
public list:string[] = [];
loadData():void {
// .. load more data for 'this.list'
}
}
use the directive in your html templates:
<div class="scroll-container" (infiniteScroll)="loadData()">
<div *ngFor="let item of list" class="item">{{item}}</div>
</div>
(infiniteScroll)="loadData()"
loadData()
method will be called when scroll reaches the bottom.
.scroll-container
class should most include max-height
and overflow:scroll
or overflow:auto