繁体   English   中英

subscribe 在 Ionic 中已弃用

[英]subscribe is deprecated in 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')
});


暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM