I have tried using ngx-infinite-scroll (https://www.npmjs.com/package/angular2-infinite-scroll) and also some other directives but none seem to work.
package
You have to set height of your container div
<div class="row" style="height: 90%"
infiniteScroll [infiniteScrollDistance]="0"
[infiniteScrollThrottle]="300" (scrolled)="loadMore()">
<div class="col-md-3 col-sm-4" *ngFor="let user of userList">
<span>{{user.name}} ({{user.email}})</span>
</div>
</div>
<div
[infiniteScrollDistance]="2"
[infiniteScrollUpDistance]="1.5"
[infiniteScrollThrottle]="100"
(scrolled)="onScrollDown()"
[scrollWindow]="false"class="search-results">
<div *ngFor="let user of userList">
<span>{{user.name}} ({{user.email}})</span>
</div>
</div>
.search-results{ height : 100% overflow-y: scroll; }
use above HTML code it works fine --ngx-infinite-scroll
Inside the document has mentioned about.
By default, the directive listens to the window scroll event and invoked the callback. To trigger the callback when the actual element is scrolled, these settings should be configured:
- [scrollWindow]="false"
- set an explict css "height" value to the element
Therefore, just put the height: 100% on your container and you will see the scrolled fired.
import { Component } from '@angular/core';
@Component({
selector: 'app',
styles: [
`.search-results {
height: 20rem;
overflow: scroll;
}`
],
template: `
<div class="search-results"
infiniteScroll
[infiniteScrollDistance]="2"
[infiniteScrollThrottle]="500"
(scrolled)="onScroll()"
[scrollWindow]="false">
</div>
`
})
export class AppComponent {
onScroll () {
console.log('scrolled!!')
}
}