2017-10-19 7 views
1

Dears、Ionic VirtualScroolプロパティ 'length' off nullを読み取れません

イオン3の仮想スクロールを使用しようとしていますが、機能しません。

私は私のプロバイダでこの機能を持っている:

constructor(public navCtrl: NavController, public navParams: NavParams, public loadingCtrl: LoadingController, public adProvider: AdProvider) { 
    this.loading = this.loadingCtrl.create(); 
    this.loading.present(); 

    this.ads = this.adProvider.getActiveAds().valueChanges() 
    this.ads.subscribe((cat)=> { 
     this.loading.dismiss() 
    }) 
    } 

と私のするlist.htmlこの:

<ion-list no-lines [virtualScroll]="ads | async"> 
     <button ion-item *virtualItem="let ad" (click)="onAdSelect(ad)" class="aero-item "> 
      <ion-thumbnail item-start> 
       <img src="assets/images/noimage.jpg" /> 
      </ion-thumbnail> 
      <h2>{{ ad.model}}</h2> 

     </button> 
    </ion-list> 

と私のリストページで

getActiveAds(){ 
    return this.afDb.list<AngularFireList<any>>('/ads-active', ref => ref.orderByChild('adPlanPriority').startAt(1).endAt(3)) 
    } 

を、私はこれを持っていますこのコード、私はこのエラーが表示されます:

Cannot read property 'length' of null 
TypeError: Cannot read property 'length' of null 
    at VirtualScroll._stepDOMWrite (http://localhost:8100/build/vendor.js:92118:60) 
    at http://localhost:8100/build/vendor.js:92078:23 
    at dispatch (http://localhost:8100/build/vendor.js:20601:9) 
    at DomController._flush (http://localhost:8100/build/vendor.js:20545:13) 
    at rafCallback (http://localhost:8100/build/vendor.js:20534:22) 

私は間違っていますか?

+0

私はvirtualScrollがasyncで動作するかどうかわかりません。 ngForに置き換えて、結果を参照してください – Duannx

答えて

0

私は同じ問題を抱えており、最適ではありませんが、回避策が見つかりました。

あなたがから見るthe documentation[virtualScroll]を参照してください。あなたのthis.adsを観察している間に観察可能な。だからあなたはCannot read property 'length' of nullを得ている。

回避方法:最初に購読してから(非同期パイプなしで)表示し、完了したらサブスクライブしないように注意してください。

ads: any[] = []; 
constructor(public adProvider: AdProvider) { 
    this.adProvider.getActiveAds().valueChanges().subscribe(results => this.ads = results); 
    } 
+0

私はあなたが言ったようにしますが、今、別のエラーが表示されます: "nullのプロパティ 'dispose'を読み取ることができません –

+0

多分あなたはこの[ (https://github.com/vuhieptran95/myFirstIonicApp)Observableにvirtualscrollを適用する**スピーカーページ**に注意してください。 –

関連する問題