无限滚动 Ionic 2 错误

Infinite scroll Ionic 2 error

我正在尝试在我的应用程序上实现无限滚动,但出现 Property "then" does not exist on type "void" 错误。当到达页面底部时,这会出现在我的文本编辑器和控制台中。这是从

的 http get 中提取的
perpage:number = 50;

loadCategory1(start:number=0) {
  var url = "http://api.yummly.com/v1/api/recipes?_app_id=////&_app_key=////";

  if (this.Category1) {
    return Promise.resolve(this.Category1);
  }

  return new Promise(resolve => {
    this.http.get(url + "&allowedAllergy[]=396^Dairy-Free&allowedAllergy[]=393^Gluten-Free&maxResult=" + this.perpage + "&start=" + start)
      .map(res => res.json())
      .subscribe(data => {
        console.log(data);
        this.Category1 = data.matches;
        resolve(this.Category1);
      });
  });
}

相关代码为

export class Category1Page {
  public api: any;
  private start:number=0;

  constructor(public navCtrl: NavController, public navParams: NavParams, public apiAuthentication: ApiAuthentication) {
    this.loadRecipes();
  }

  loadRecipes(){
    this.apiAuthentication.loadCategory1(this.start)
    .then(data => {
      this.api = data;
    });
  } 

  doInfinite(infiniteScroll:any) {
     console.log('doInfinite, start is currently '+this.start);
     this.start+=50;

     this.loadRecipes().then(()=>{
       infiniteScroll.complete();
     });
  }
}

HTML

 <ion-infinite-scroll (ionInfinite)="doInfinite($event)">
   <ion-infinite-scroll-content></ion-infinite-scroll-content>
 </ion-infinite-scroll>

任何指点都很好,谢谢。

Property "then" does not exist on type "void"

您的 loadRecipes 方法未返回任何内容(因此它是无效的)并且您正试图在

中调用 then()...
this.loadRecipes().then(()=>{
       infiniteScroll.complete();
     });

尝试添加 return 关键字,如下所示:

loadRecipes(){
    return this.apiAuthentication.loadCategory1(this.start)
    .then(data => {
      this.api = data;
    });
  }