To populate an Ionic list with items, push strings into the list using the InfiniteScroll feature

Looking for help with implementing infinite scroll in a list? I am using the ion-infinite-scroll directive but struggling to push string values into my list. The list contains names of students in a classroom. Can anyone provide guidance on how to push strings into the list and call the complete() method?

.html

            <h2>{{item.name}}</h2> 
        </ion-item>
    </ion-list>
    <ion-infinite-scroll (ionInfinite)="loadMore($scope)">
        <ion-infinite-scroll-content>
        </ion-infinite-scroll-content>
    </ion-infinite-scroll>

.ts

export class NotificationsPage {
i: number;
items: any = [];
name: any;
InfiniteScroll: any;
constructor(public navCtrl: NavController, public navParams: NavParams) {
    for (let i = 0; i < 10; i++) {
        let item = {
            name:i,
        };
        this.items.push(item);
    }

    this.InfiniteScroll.complete()


}
loadMore(InfiniteScroll: any) {
    this.objects.items.push({this.items});

};

ionViewDidLoad() {
    console.log('ionViewDidLoad NotificationsPage');
};

}

Answer №1

Follow these steps for a solution on Plunker

HTML

<ion-content padding>
    <ion-list *ngFor="let item of items">
        <h2>{{item?.name}}</h2>
    </ion-list>
    <ion-infinite-scroll (ionInfinite)="loadMore($event)">
        <ion-infinite-scroll-content>
        </ion-infinite-scroll-content>
    </ion-infinite-scroll>
</ion-content>

TS:

import {  Component } from '@angular/core';
import {  NavController } from 'ionic-angular';

@Component({
    selector: 'page-home',
    templateUrl: 'app/home.page.html'
})
export class HomePage {
    items: any = [];
    constructor(public navCtrl: NavController) {}
    load() {
        for (let i = 0; i < 10; i++) {
            let item = {
                name: i,
            };
            this.items.push(item);
        }
    }
    loadMore(InfiniteScroll: any) {

        this.load();
        InfiniteScroll.complete();
    };

    ionViewDidLoad() {
        this.load();
    };
}

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

Angular 10 - Understanding the R3InjectorError in AppModule related to Window constant injection

I'm attempting to access the window object in Angular using a service that can be injected. import { Injectable } from '@angular/core'; function _window(): any { return window; } @Injectable({ providedIn: 'root' }) export cla ...

What is the best way to invoke a method in a child component from its parent, before the child component has been rendered?

Within my application, I have a parent component and a child component responsible for adding and updating tiles using a pop-up component. The "Add" button is located in the parent component, while the update functionality is in the child component. When ...

What is the reason behind installing both Typescript and Javascript in Next.js?

After executing the command npx create-next-app --typescript --example with-tailwindcss my_project, my project ends up having this appearance: https://i.stack.imgur.com/yXEFK.png Is there a way to set up Next.js with Typescript and Tailwind CSS without i ...

The error message "The function 'combineLatest' is not found on the Observable type"

Hey there! I'm currently working on implementing an InstantSearch function into my website using Angular 12.2. To accomplish this, I'll be working with a Firestore database with the index "book-data". In my search component, I have included the f ...

Encountering an issue in Angular 8 where a class is not being added after the page loads, resulting in an

Looking to dynamically add a class to a div element using Angular? I have a condition isTrue, and am utilizing the angular function ngAfterViewInit() to add the class hideOnLoad after the page loads when isTrue becomes true. Instead of traditional javascri ...

The Excel Match function is experiencing issues when used in conjunction with the MS-Graph API

Recently, I've encountered an issue with sending a match-function post request to an Excel workbook using the MS-Graph API. Instead of receiving the value of the first column that contains the lookup value, I'm getting the value from the second c ...

Fetching JSON data from a Node.js server and displaying it in an Angular 6 application

Here is the code snippet from my app.js: app.get('/post', (req,res) =>{ let data = [{ userId: 10, id: 98, title: 'laboriosam dolor voluptates', body: 'doloremque ex facilis sit sint culpa{ userId: 10' ...

Unable to access attribute of instantiated class

I am relatively new to TypeScript and I recently encountered a problem that's stumping me. I'm working on setting up a REST API using Express. The setup involves a router that calls a controller, which in turn invokes a service method before ret ...

I'm looking for a sample of RadPieChart for nativescript + angular. Can anyone help me out?

I'm currently working on a multi-platform application that requires a PieChart to be displayed on the main screen. Can someone point me to a comprehensive example of how to implement this? I have tried following this guide and modifying it according ...

Is it possible to receive a notification when the DOM elements of an Angular 2+ component are successfully rendered in the browser?

I have a parent component in Angular that contains over 1000 DOM nodes. These nodes are rendered using two ngFor cycles, resulting in a 2D table structure. Each of these DOM nodes is an individual Angular component. The styles and displayed values of these ...

What is the best method to display a tooltip for a disabled radio button within a set of radio buttons?

Is there a way to disable a specific radio button based on a condition and display a tooltip only for that disabled button? https://i.stack.imgur.com/niZK1.png import {Tooltip} from '@mui/material'; <Tooltip titl ...

I am in search of a method to rephrase the content while minimizing redundancy

I am looking to improve the code for handling two different conditions in the UI. Can someone suggest a better way to rewrite it? <i *ngIf="measures.length > 0"> <ul *ngFor="let m of measures"> <io-data-selection-row [text] ...

Using a reactive form in Angular 12, the selected form group is initialized with an empty array

.html File <div *ngFor="let analysis of analysisFormArray.controls; let i = index" [class.selected]="analysis === selectedAnalysis"> <div [formGroup]="analysis" (click)="onSelect(analysis)"> ...

What is preventing the mat-slide-toggle from being moved inside the form tags?

I've got a functioning slide toggle that works perfectly, except when I try to move it next to the form, it stops working. When placed within the form tag, the toggle fails to change on click and remains in a false state. I've checked out other ...

Initializing various objects on the same interface type array in one line

Is there a way to inline initialize an array of the interface type IFooFace in TypeScript with different specific implementations, similar to how it can be done in C#? Or do I have to initialize my objects before the array and then pass them in? In C#, th ...

Update the name of the table header dynamically based on the checkbox that is selected in Vue

I am working on a project where I have checkboxes that determine the header of my table based on selection. Starting from <th>Default</th>... If checkbox1 is checked, the header will change to "CheckBox1". If checkbox2 is checked, the header ...

What is the connection between @types, TypeScript, and Webpack?

When using an exported type in a .ts file, it is necessary to import it: import {jQuery} from 'jQuery' Even after adding the import, intellisense may not work until npm install @types\jQuery is executed. If @types are installed, intellis ...

Reacting to the surprise of TS/JS async function behaving differently than anticipated

It appears that I'm facing a challenge with the small method; not sure if my brain is refusing to cooperate or what's going on. async fetchContacts() { await this.http.get('http://localhost:3000/contacts') .subscribe(res =& ...

After the rendering process, the React Component member goes back to a state of

One issue I encountered is related to a component that utilizes a separate client for making HTTP requests. Specifically, when trying to use the client within a click event handler, the call to this.client.getChannel() fails due to this.client being undefi ...

Angular2 calendar and time selector

Having trouble setting up a date and time picker for my angular2 app. Can anyone provide assistance with this? I've experimented with the following methods: Ng2-datetime: I added it to the main app.module file: import { NKDatetimeModule } from &ap ...