代码之家  ›  专栏  ›  技术社区  ›  Tom

类型“Promise”上不存在属性“pipe”

  •  -2
  • Tom  · 技术社区  · 6 年前

    错误TS2339:类型“Promise”上不存在属性“pipe”。 类型“void”不能分配给类型“observateinput”

    从“rxjs/operators”导入{map,catchError};

    saveFund() {
            if (this.SelectedFundId === 0) {
                this.fundService.createFund(this.FundDetails).then((result) => {
                    if (result) {
                        this.getFundDetails(this.SelectedFundId);
                        this.EditMode = !this.EditMode;
                    }
                });
            } else {
                this.fundService.updateFund(this.FundDetails).then((result) => {
                    if (result) {
                        this.getFundDetails(this.SelectedFundId);
                        this.notify.success('Fund Details Successfully Updated');
                        this.EditMode = !this.EditMode;
                    }
                }) .pipe(catchError (err => {
                    this.notify.error('An Error Has Occured While Updating Fund Details');
                }));
            }
        }
    
    3 回复  |  直到 6 年前
        1
  •  0
  •   Milos Kovacevic    6 年前

    不能使用“pipe”运算符,因为它是 rxjs运算符 . 在你的情况下你可以使用 捕获(错误)

    saveFund() {
        if (this.SelectedFundId === 0) {
            this.fundService.createFund(this.FundDetails).then((result) => {
                if (result) {
                    this.getFundDetails(this.SelectedFundId);
                    this.EditMode = !this.EditMode;
                }
            }).catch(err => {
               this.notify.error('An Error Has Occured While Creating Fund Details');
            });
        } else {
            this.fundService.updateFund(this.FundDetails).then((result) => {
                if (result) {
                    this.getFundDetails(this.SelectedFundId);
                    this.notify.success('Fund Details Successfully Updated');
                    this.EditMode = !this.EditMode;
                }
            }).catch(err => {
                this.notify.error('An Error Has Occured While Updating Fund Details');
            });
        }
    }
    

    希望这对你有用!

        2
  •  0
  •   Tachyon    6 年前

    pipe 作为一种方法 Observable 你需要使用 .then() .catch() 后者是处理承诺错误的方法

        3
  •  0
  •   Vadi    6 年前

    是一种方法 ,它应该和 Observables 承诺 抓住 方法如下:

    this.fundService.updateFund(this.FundDetails)
      .then((result) => {
        if (result) {
          this.getFundDetails(this.SelectedFundId);
          this.notify.success('Fund Details Successfully Updated');
                    this.EditMode = !this.EditMode;
        }
      })
      .catch(err => console.log(err));