Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ionic 4 virtual scroll not working

I created new project with Ionic 4. I have an array of item (spaces) in typescript file and I want to show them in template file by Ionic virtual scroll:

    <ion-list [virtualScroll]="spaces" approxItemHeight="320px">
      <ion-card *virtualItem="let space">
        <div>
          <ion-img [src]="space.picture"></ion-img>
        </div>
        <ion-card-header>
          <ion-card-title>{{ space.place}}</ion-card-title>
        </ion-card-header>
        <ion-card-content>{{ space.price}}</ion-card-content>
      </ion-card>
    </ion-list>

But I get an error with Ionic virtual scroll:

Can't bind to 'virtualScroll' since it isn't a known property of 'ion-list'.

What wrong with my code. Please help me, Thanks.

like image 533
Nhan Avatar asked Jul 23 '18 09:07

Nhan


1 Answers

I was facing the same issue, and after a lot of digging through the v4 beta docs and the issues on GitHub, I found that your syntax (and mine) wasn't right: the parent should be an <ion-virtual-scroll> component with an [items] property binding, rather than an <ion-list> with a [virtualScroll] property binding.

<ion-virtual-scroll [items]="spaces" approxItemHeight="320px">
  <ion-card *virtualItem="let space">
    <div>
      <ion-img [src]="space.picture"></ion-img>
    </div>
    <ion-card-header>
      <ion-card-title>{{space.place}}</ion-card-title>
    </ion-card-header>
    <ion-card-content>{{space.price}}</ion-card-content>
  </ion-card>
</ion-virtual-scroll>
like image 131
Joris Avatar answered Nov 06 '22 15:11

Joris