且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Ionic VirtualScroll 无法读取 null 的属性“长度"

更新时间:2023-12-03 16:40:10

I got the same issue and found a workaround, although it's not optimal.

You see from the documentation [virtualScroll]expect an Array. While your this.ads return an Observable. That's why you got Cannot read property 'length' of null.

Workaround: Subscribe to it first then display on view (without async pipe), also keep in mind to unsubsribe when done.

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