简体   繁体   English

Angular报错“toPromise is not a function”有解决办法吗?

[英]Is there a solution to the error "toPromise is not a function" in Angular?

I keep getting this error while testing: Uncaught Error: Uncaught (in promise): TypeError: this._productService.getProducts(...).toPromise is not a function.我在测试时不断收到此错误:未捕获错误:未捕获(承诺):TypeError:this._productService.getProducts(...).toPromise is not a function。

I know that toPromise is being deprecated in rxjs version 7 but I am running version 6. Is there a way to fix this or another way to write my code without using a toPromise?我知道 toPromise 在 rxjs 第 7 版中已被弃用,但我正在运行第 6 版。有没有办法在不使用 toPromise 的情况下解决这个问题或另一种方法来编写我的代码?

I am getting my products based on the three inputs already defined based on a previous click.我正在根据之前单击定义的三个输入来获取我的产品。

Thank you.谢谢你。

    async ngOnInit(): Promise<void> {
    this.product = await this._productService
      .getProducts({
        InputOne: this.inputOne,
        InputTwo: this.inputTwo,
        InputThree: this.inputThree
      })
      .toPromise();
  }

Since RxJS 7.0 toPromise() is deprecated and replaced by firstValueFrom or lastValueFrom depending on what you want to do.由于 RxJS 7.0 toPromise()已弃用并由firstValueFromlastValueFrom替换,具体取决于您想要做什么。

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

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