Implementing Scroll Pagination in Angular 2 to Showcase Information

Recently delving into Angular2, my aim is to set up Scroll Pagination for dynamic data loading upon user scrolling.

My application comprises three key Components: App.Component, Categories.Component, and Products.Component.

The primary objective is to present products in a paginated manner. Below is the code snippet from Products.Component:

@Component({
selector: 'products',
template: `<div class="products-wrapper grid-4 products clearfix loading">
            <div *ngFor="#product of products"  (click)="getProduct(product)" class="product">
                <div class="product-inner" style="background:url({{product.pictureUrl}})">
                    <div class="time-left">
                        <span class="text">Hourly Deal</span>
                        <ul class="countdown clearfix">
                            <li> 
                                <div class="text">
                                    <span class="hours">00</span>
                                </div>
                            </li>

                            <li> 
                                <div class="text">
                                    <span class="minutes">00</span>
                                </div>
                            </li>
                            <li> 
                                <div class="text">
                                    <span class="seconds">00</span>
                                </div>
                            </li>
                        </ul>
                    </div>
                    <span class="discount-tag">{{product.discount}}%</span>

                </div>
            </div>
            </div>`,
            providers :[CategoryService]

})
@Injectable()
export class ProductsComponent {
private product:ProductModel;
private products: ProductModel[] = [];
constructor(private _categoryService : CategoryService)
{
    this._categoryService.getProducts(0)
    .subscribe(
        a=>{
            this.products = a;
        }
    );
}
getProduct(product:ProductModel)
{
    alert(product.productId);
    this.product = product;
}
populateProducts(products: ProductModel[] = [])
{
    this.products = products;
}


}

To enable pagination of products when reaching the bottom of the scroll on the page, your assistance would be greatly appreciated.

Please provide guidance. Thank you.

Answer №1

import {Component} from 'angular2/core'

@Component({
  selector: 'my-app',
  template: `
    <div (window:scroll)="onScrollHandler($event)">
      <h1>Greetings from Angular2</h1>
      <div class="" *ngFor="let row of array">

</div>
    </div>
  `,
})
export class AppComponent {

  onScrollHandler(event) {
    console.log('scroll event', event);
  }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I incorporate an interface and specify a particular type as the return value in TypeScript?

interface Inter{ str:string } function func(){ let v:Inter={ str:'abc' }; return v; } func()//Is there a way to ensure that the type of value returned from `func` is {str:'abc'} without explicitly declaring it i ...

Steps to resolve the issue with "Error: StaticInjectorError(AppModule)[NgbDropdown -> ChangeDetectorRef]"

My attempt at creating a web app using Angular resulted in successful compilation with no errors. However, upon execution, the browser displays a blank page accompanied by the following error message: ERROR Error: Uncaught(in promise): Error: St ...

Turn off the dynamically generated multiselect dropdown feature (using a plugin) in an angular application

I have included a multi-select dropdown in each row of a table, allowing the user to modify the selection and save it. The configuration for the multi-select dropdown is stored in a TypeScript file. Now, I am looking to disable the dropdown in certain ro ...

Typescript: Establishing a class method with parameters that are inherent to the class

After creating a class, I realized that there is repeated logic that can be extracted into a method on the class to be reused by other properties of the class. class Card { protected readonly data: Data; protected readonly user: User; nameVal: strin ...

Is it possible to use ng-bootstrap with vertical tabs?

I'm experimenting with displaying ng-Bootstrap tabs vertically, but the provided example doesn't quite fit my needs. I'm envisioning a layout similar to what I've sketched in the diagram. Do you think it's achievable? Any suggestio ...

What is the best way to combine various express routes from separate files in a TypeScript project?

After transitioning to TypeScript, I have been facing issues with merging different routes from separate .ts files. In JavaScript, I used to combine routes like this: app.use("/users/auth", require("./routes/user/auth")); app.use("/users", require("./rou ...

Unable to employ the inequality operator while querying a collection in AngularFire

I'm facing a challenge with pulling a collection from Firebase that is not linked to the user. While I've managed to query the user's collection successfully, I am struggling to retrieve the collection that does not belong to the user using ...

"Investigating the impact of import quantities on the total size of an Angular production bundle

I searched for an answer but couldn't find one to address my fundamental question. I am currently constructing an Angular App and encountered a situation where I wanted to switch out the angular material components with ionic web components. However, ...

Troubleshooting Problems with Angular 6 Inheritance

After creating a base class named AncientWisdom and multiple subclasses representing different aspects of ancient wisdom, I encountered an issue in Angular. When the end value triggers the logic for exceeding the maximum unlocks, all subclasses inheriting ...

Step-by-step guide on building a wrapper child component for a React navigator

When using the Tab.Navigator component, it is important to note that only the Tab.Screen component can be a direct child component. Is there a way in Typescript to convert or cast the Tab.Screen Type to the TabButton function? const App = () => { retur ...

Utilize the reducer from another slice in Redux Toolkit

I am working with an authSlice const authSlice = createSlice({ name: 'authStore', initialState, reducers: { logout(state = initialState) { return { ...state, isAuthenticated: false }; }, }, extraReducers: (builder) => { ...

Utilizing Angular and Cordova within a Virtual Directory

In an Angular application running in a virtual directory (https://{url}/{virtualDirectory}), I am attempting to encapsulate it within a Cordova application that references the same URL as the content source (<content src="https://{url}/{virtualDire ...

React: Content has not been refreshed

MarketEvent.tsx module is a centralized controller: import * as React from 'react'; import EventList from './EventList'; import FullReduce from './FullReduce'; import './MarketEvent.less' export default class Mark ...

Can you tell me which version of Angular is the most reliable and stable?

I am currently running version 9.0.7 of Angular. Could someone recommend a stable version of Angular to use? ...

What is the best way to update my data from the parent component?

Hello, I am trying to update the timestamp value from the parent component. This is my ParentComponent.ts file: public updateTimestamp(){ this.timestamp = new Date(); this.timestamp.setDate(this.timestamp.getDate() - 30); this.timestamp = thi ...

Cross-origin resource sharing problem (Backend developed in Express, Frontend in Angular)

I am currently utilizing Angular for my front-end development and Express for the back-end. I encountered a CORS issue with one of multiple API endpoints that have similar configurations: Failed to load http://localhost:3000/api/deletePost: No 'Acc ...

Which `target` is best for Node 11 in TypeScript?

With TypeScript's target configuration offering various values such as esnext, es2015, and es6, it can be a bit confusing to decide which one to choose. The latest version of NodeJs (11.11.0) supports many new JavaScript features. But is it recommend ...

Angular 4's ngOnChanges method does not display the updates made

I've been attempting to utilize ngOnChanges in Angular 4, but I haven't been able to get it to work. login.component.ts import { AuthService } from './../../services/auth.service'; import { ActivatedRoute, Router } from '@ang ...

An issue has occurred with the NullInjector, specifically regarding the AppModule and Storage in Ionic 4

When attempting to launch my Ionic app using npm start, an error message appears stating "NullInjectorError: No provider for Storage!". I have already included Storage in the app.module.ts file as shown below: imports: \[ BrowserModule, IonicModule ...

Guide on implementing JWT authentication in API using Nebular Auth

I have implemented Nebular auth for my Angular application. I am trying to include a token in the header when a user logs in. Below is the API response: { "status": 0, "message": null, "data": { "type": &qu ...