首页 > 解决方案 > Ionic 4 Refresher 没有传入 refresher 对象,所以我无法完成它

问题描述

尝试完成复习时,出现错误

TypeError: refresher.complete 不是一个函数。

.html:

<ion-refresher #refresherRef slot="fixed" (ionRefresh)="load($event)">
    <ion-refresher-content
    pullingIcon="arrow-dropdown"
    pullingText="Pull to refresh"
    refreshingSpinner="circles"
    refreshingText="Refreshing...">
    </ion-refresher-content>
  </ion-refresher>

.ts

load(refresher) {
    let postData = new FormData();
    postData.append('user_id', this.userData.userId);

    this.authService.postData(postData, "is_verified_or_not.php").then((result) => {
      this.responseData = result;

      this.success = this.responseData.success;
      if (this.success == 1) {
        refresher.complete();
        let userDeatil = this.responseData.users_details;
        for (let data1 of userDeatil) {
        }
      } else {
        this.message = this.responseData.message;
        refresher.complete();
        this.showToast(this.message);
      }
    }, (err) => {
      refresher.complete();
      console.log("Error", err);
    });
  }

我按照https://forum.ionicframework.com/t/ionic-4-refresher-is-not-passing-in-the-refresher-object-so-i-cant-complete-it/144213的说明进行操作

我试过了:

@ViewChild("refresherRef") refresherRef: Refresher;

load(refresher: Refresher) {
    this.refresherRef.complete();
}    

但这给了我一个错误@ViewChild("refresherRef")

预期 2 个参数,但得到 1.ts(2554) core.d.ts(8436, 47):未提供“opts”的参数。

在同一行的Refresher@ViewChild("refresherRef") refresherRef: Refresher;

找不到名称“Refresher”。

标签: angularionic4swiperefreshlayoutpull-to-refresh

解决方案


在 Angular 8 中, ViewChild 需要 2 个参数

尝试更换

@ViewChild("refresherRef")

@ViewChild("refresherRef", { static: false } )


推荐阅读