首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >为什么` is ()` observable没有执行next()?

为什么` is ()` observable没有执行next()?
EN

Stack Overflow用户
提问于 2019-02-22 03:55:31
回答 2查看 129关注 0票数 1

我有这样的情况:

 this._userService
            .create(user)
            .pipe(
                switchMap(res => {
                    if (this.accountStore.accounts.length > 0) {
                        return this._accountsService.manageAccounts(
                            accounts,
                            res.idUser
                        );
                    } else return of();
                })
            )
            .subscribe(
                _ => {
                    this._router.navigate(["/app/main/user/"]);
                },
                () => (this.saving = false)
            );

如果帐户高于0,则工作正常。但是如果它转到else块,return of()就不会执行next()来导航到用户路由;

我做错了什么?

EN

回答 2

Stack Overflow用户

发布于 2019-02-22 05:09:59

您需要将一个值传递给of以执行next operator或subscriber。在本例中,我只是将null作为of(null)传递

票数 1
EN

Stack Overflow用户

发布于 2019-02-22 04:02:18

this answer相似,但由于版本不同,您需要使用of({}).pipe(take(1))创建一个空对象observable并调用next。

对于您的代码:

...
} else return of({}).pipe(take(1));
...
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54815229

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档