question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Working with ionic?

See original GitHub issue

Is it working with Ionic3?

I tried but it’s rendering all the items instead of only the ones in the content viewport.

Then I tried to pass the Ionic content with:

<virtual-scroll [items]="companies" (update)="viewPortItems = $event"  parentScroll="content">
    <div *ngFor="let company of viewPortItems">
      <company-stats [company]="company" ></company-stats>
    </div>
</virtual-scroll>

content variable is defined in my page with


export class CompaniesPage {
  @ViewChild(Content) content: Content;
   // more stuff here
}

But I got a Uncaught (in promise): TypeError: parentScroll.addEventListener is not a function

Any ideas? Someone sucessfully implemented it in Ionic?

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:15 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
Melcuscommented, Mar 29, 2018

The way I got it working for me flawlessly, even with the changing number of elements in the list and images :

HTML

<virtual-scroll [parentScroll]="_content?.getScrollElement()" [ngStyle]="getScrollHeight()"
  [items]="items" (update)="viewPortItems = $event " [childHeight]="96" [bufferAmount]="25">
  <ion-item *ngFor="let media of viewPortItems">

    <ion-thumbnail item-start (click)="clickThumbnail(media)">
      <ng-container *ngIf="media.image; else second">
        <ion-img [src]="media.img_path"></ion-img>
      </ng-container>

      <ng-template #second>
        <ng-container>
          <i class="{{media.icon}}"></i>
        </ng-container>
      </ng-template>
    </ion-thumbnail>

    <div (click)="clickBody(media)" class="text-elipsis" tappable>
      <h2 [innerHTML]="highlight(media.subject, search_key)" class="text-elipsis"></h2>
      <p [innerHTML]="highlight(media.createdate, search_key)" class="text-elipsis"></p>
      <p [innerHTML]="highlight(media.mediatext, search_key)" class="text-elipsis"></p>
    </div>
  </ion-item>
 </virtual-scroll>

CSS

.text-elipsis {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
} 

To keep the heights consistent.

TS

Below export class @ViewChild(Content) _content: Content;

After you get the data from SQL or whatever, set the [bufferAmount] of elements in viewPortItems so it renders correctly

this.viewPortItems = this.items.length > 25 ? _.slice(this.items, 0, 25) : _.cloneDeep(this.items);

Also add this function . Replace 96 with the height of your element ( childHeight was quite buggy with this one )

getScrollHeight() {
    let styles = {};
    if (this.items.length) {
      styles = {
        'display': 'block',
        'width': '100%',
        'height': this.items.length * 96 + 'px'
      };
    }
    return styles;
}
2reactions
belliziocommented, Aug 23, 2017

How did everyone get this to work with Ionic 3?

After installation and adding the markup to my view, I can’t get past this error: Uncaught (in promise): Error: Template parse errors: Can't bind to 'items' since it isn't a known property of 'virtual-scroll'.

Update: I figured out the issue. I had to import the VirtualScrollModule into the child module (where I’m using virtual-scroll) instead my global app module. I imagine it has something to do with the fact that I’m using lazy-loading for components.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Build Your First Ionic Mobile App: Angular Development Tutorial
Ionic's single codebase builds for any platform using just HTML, CSS, & JavaScript. Develop your first mobile app with our step-by-step Angular tutorial....
Read more >
How to Get Started with Ionic and Angular
Ionic is a framework that allows us to develop mobile apps and websites using web technologies – HTML, CSS and Javascript basically. The...
Read more >
Ionic Tutorial - Tutorialspoint
Ionic is open source framework used for developing mobile applications. It provides tools and services for building Mobile UI with native look and...
Read more >
Ionic Tutorial: Build a complete mobile app with Ionic Framework
The most complete Getting Started with Ionic Framework guide ever built. Learn the core concepts of Ionic while building a real mobile app....
Read more >
Ionic Tutorial #1 - Overview, installation and creating the project
In this video I will show you a brief summary about the idea of the Ionic Framework, how to install it on your...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found