【发布时间】:2020-11-03 14:24:05
【问题描述】:
我在 subscribe 中有一个订阅,我想链接它,但我不确定我应该如何继续,因为实习生订阅在 if 块内。
authenticationService.isLoggedIn$.subscribe(isLoggedIn => {
this.isLoggedIn = isLoggedIn;
if (isLoggedIn) {
socketService.initSocket();
authenticationService.refresh().subscribe(time => {
this.timeOut = time.expirationTime;
this.setTimeout(this.timeOut);
});
} else {
clearTimeout(this.userActivity);
socketService.destroySocket();
}
});
我很想以某种方式链接它,以便只能订阅一次。 我在想把它放在一个可以顺序运行它的数组中会很好吗?
【问题讨论】:
-
你能详细说明一下吗?我不确定你在这里实际问的是什么。
-
我想避免在subscribe()中有subscribe(),而是包含代码的逻辑。
标签: angular rxjs angular2-observables