Angular 4: Infinite scroll not working

后端 未结 3 1898
北荒
北荒 2020-12-30 06:20

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

相关标签:
3条回答
  • 2020-12-30 06:50

    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>
    
    0 讨论(0)
  • 2020-12-30 06:51
           <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

    0 讨论(0)
  • 2020-12-30 06:53

    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:

    1. [scrollWindow]="false"
    2. 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!!')
        }
    }
    
    0 讨论(0)
提交回复
热议问题