根据订阅处理2个?角

发布于 2025-02-09 06:44:00 字数 219 浏览 2 评论 0原文

我有一个与此代码的组成部分,

this.service().subscribe((result) => { this.service2(result).subscribe((result2) => //other code }}

我正在使用Angular进行良好的实践,这似乎不是这种代码的好方法。但不确定如何改善这一点。

有建议吗?

I have a component with this code

this.service().subscribe((result) => { this.service2(result).subscribe((result2) => //other code }}

I'm applying good practices in Angular and seems this is not a good approach for this kind of code. But not sure how to improve this.

any suggestion?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

白龙吟 2025-02-16 06:44:00

使用switchmap操作员:

this.service.getSomething().pipe(
    switchMap(result1 => this.service.getSomething2())
)

Use switchMap operator:

this.service.getSomething().pipe(
    switchMap(result1 => this.service.getSomething2())
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文