ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

VirtualScroll component is not showing when use it inside a directive

Open g-serghei opened this issue 10 years ago • 10 comments

Short description of the problem:

I have created a new component items-list, inside that component I use virtualScroll component, when I pass an array to items-list component

<items-list [items]="items"></items-list>

it shows nothing on the page, but when I insert some characters before virtualScroll component - it works well...

some chars...
<ion-list [virtualScroll]="items">
  <button *virtualItem="let item" ion-item>
    {{item}}
  </button>
</ion-list>

What behavior are you expecting?

virtualScroll component must show up on the page

I use Ionic Framework Version: 2.0.0-beta.8

Steps to reproduce:

  1. Create a new component
  2. In the view of created component add virtualScroll
  3. Use created component on a page and pass to it a list of data which will be shown by virtualScroll
  4. see that there is nothing on the page
  5. add some characters before virtualScroll component
  6. see that the list appears on the page

This is Plunker that shows an example of the issue

http://plnkr.co/edit/ONionfMEuPb9tY8fAK5e?p=preview

g-serghei avatar Jun 13 '16 08:06 g-serghei

I'd like to propose generalizing this issue as I can reproduce this even without a custom directive. I believe the root cause is actually the <button> element that's being used as the *virtualItem. I swapped out the <button> for <ion-item> and it starts showing up.

Here's the gist of what I have

<ion-content>
  <ion-list [virtualScroll]="items">
    <button ion-item *virtualItem="let item">
      {{ item.text }}
    </button>
  </ion-list>
</ion-content>

I can also reproduce using the adding random characters hack before the <ion-list>, which makes things visible again.

wli avatar Jun 14 '16 23:06 wli

I tried to reproduce this as you said without a custom directive, and it work fine even when using <button> as the *virtualItem.

here is the Plunker http://plnkr.co/edit/rZDgBoDMnKTnlGScSqbn?p=preview

but when use it inside a custom directive, the problem remained even when I swapped out the <button> for <ion-item>.

<ion-list [virtualScroll]="items">
  <ion-item *virtualItem="let item">
    {{item}}
  </ion-item>
</ion-list>

here is the Plunker http://plnkr.co/edit/5nwRRGrBqq07rv2k5DNs?p=preview

Thank you.

g-serghei avatar Jun 15 '16 06:06 g-serghei

The problem occurs even if ion-list has any parent element: here is a plunker with a toggle where you can switch between this tow scenarios. http://plnkr.co/edit/quAFRkyM9B9pxpFU69Fo?p=preview

DavidWiesner avatar Jun 17 '16 08:06 DavidWiesner

found the solution:

items-list{
  overflow: hidden;
  display:block;
}

See index.html in http://plnkr.co/edit/7cj5DfOnGGmi6ss94c3a?p=preview

DavidWiesner avatar Jun 17 '16 08:06 DavidWiesner

I tried and it really solved the problem.. I don't know why the problem occurs.. but for now this is a good solution

Thank you @DavidWiesner

g-serghei avatar Jun 17 '16 09:06 g-serghei

I think it uses the parent for scrolling/height calculations etc.

maxx0r avatar Nov 15 '16 08:11 maxx0r

Thank you @DavidWiesner

And set wrapper height also

dtmp avatar Jun 15 '17 20:06 dtmp

I just got a variant of this one (instead of no list entries I got all at once which froze the browser as there were about 2k)

The effective workaround, in the end, was to tell the directive div itself how big it should be. I did it from within the directive using the css :host selector:

:host {
	position: absolute;
	top: 0;
	bottom: 0;
	left: 0;
	right: 0;
}

Farbdose avatar Nov 13 '17 16:11 Farbdose

Thanks for the issue! We have moved the source code and issues for Ionic 3 into a separate repository. I am moving this issue to the repository for Ionic 3. Please track this issue over there.

Thank you for using Ionic!

ionitron-bot[bot] avatar Nov 01 '18 19:11 ionitron-bot[bot]

Issue moved to: https://github.com/ionic-team/ionic-v3/issues/1

ionitron-bot[bot] avatar Nov 01 '18 19:11 ionitron-bot[bot]