VirtualScroll component is not showing when use it inside a directive
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:
- Create a new component
- In the view of created component add
virtualScroll - Use created component on a page and pass to it a list of data which will be shown by
virtualScroll - see that there is nothing on the page
- add some characters before
virtualScrollcomponent - see that the list appears on the page
This is Plunker that shows an example of the issue
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.
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.
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
found the solution:
items-list{
overflow: hidden;
display:block;
}
See index.html in http://plnkr.co/edit/7cj5DfOnGGmi6ss94c3a?p=preview
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
I think it uses the parent for scrolling/height calculations etc.
Thank you @DavidWiesner
And set wrapper height also
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;
}
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!
Issue moved to: https://github.com/ionic-team/ionic-v3/issues/1