首页 > 解决方案 > Angular ngx-infinite-scroll is not working

问题描述

I am developing Angular project and using ngx-infinite-scroll for displaying a page with data from a database. As I followed the user guide for ngx-infinite-scroll, i installed it via npm and then added the module to a file, that exports all modules in array:

import {BrowserModule} from '@angular/platform-browser';
import {FormsModule} from '@angular/forms';
import {HttpClientModule} from '@angular/common/http';
import {AppRoutingModule} from '../../app-routing.module';
import { InfiniteScrollModule } from "ngx-infinite-scroll";

export const ModulesExport= [
  BrowserModule,
  FormsModule,
  HttpClientModule,
  AppRoutingModule,
  InfiniteScrollModule
];

After that, I imported that array in my app.module.ts and added it to the importing modules.

import { NgModule } from '@angular/core';

/* import all modules, services and components from package export files */
import {ProvidersExport} from './export/providers-services/export-providers';
import {ComponentsExport} from './export/components/export-components';
import {ExportComponentsObj} from './export/components/export-components-obj';
import {ModulesExport} from './export/modules/export-modules';


@NgModule({
  declarations: [...ComponentsExport],
  imports: [...ModulesExport],
  providers: [...ProvidersExport],
  bootstrap: [ExportComponentsObj.App]
})
export class AppModule { }

So after everything is added and ready to go, I created my component and included the required parameters for infinite scroll in my html component:

<div class="row center container">
  <div class="journeysWrapper" style="height: 100%" infinite-scroll [infiniteScrollDistance]="2" [infiniteScrollThrottle]="300" (scroll)="loadMore()">
    <app-journey-preview *ngFor="let journey of journeys" [journey]="journey" [journeyCount]="journeys.length" class="center row container"></app-journey-preview>
  </div>
</div>

I am now trying to test if everything works correctly and just logging a sample string when the scrolling event is triggered:

  loadMore() {
    console.log('scrolled down!!');
  }

Unfortunately, when I load the page, I get the following error:

enter image description here

So now I am stuck with this error and I cannot figure out why does it appear. Any help would be appreciated!

标签: javascriptangularscrollinfinite-scroll

解决方案


函数是 Scrolled insted scroll, (scrolled)="fn()"


推荐阅读