微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

订阅在 Ionic 中已被弃用

如何解决订阅在 Ionic 中已被弃用

我在 Ionic Proyect 中有此警告“订阅已弃用:使用观察者而不是完整回调”。请帮忙。

fetch(cb) {
    this.loadingIndicator = true;
    this.cservice.postNcRangoConta(this.body).subscribe(
      res => {
        try {
          if (res) {
            this.headers = Object.keys(res[0]);
            this.columns = this.getColumns(this.headers);
            this.temp = [...res];
            cb(res);
            this.loadingIndicator = false;
          }
        } catch (error) {
          this.loadingIndicator = false;
          this.rows = null;
          this.toast.presentToast('No se encontraron datos','warning');
        }
      },err => {
        console.log(err);
        if (this.desde || this.hasta) {

          this.loadingIndicator = false;
          this.toast.presentToast('La API no responde','danger');
        } else {
          this.loadingIndicator = false;
          this.toast.presentToast('Debe llenar las fechas','warning');
        }
      }
    );
  }

解决方法

subscribe 方法实际上并未被弃用,但您使用它的方式已被弃用。尝试切换到它的新语法。

// Deprecated
source.subscribe(
  (res) => cb(res),error => console.error(error),() => console.log('Complete')
);

// Recommended
source.subscribe({
  next: (res) => cb(res),error: error => console.error(error),complete: () => console.log('Complete')
});


版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。