主题'完整' rxjs的完整订阅并未取消订阅 - 角
RXJ的主题“完整”并未在Angular中取消订阅。
我正在使用“ takeuntil”未订阅方法。 我的应用程序中有多个订阅,我想在“ ngondestroy”中退订所有这些订阅。
我创建了以下逻辑:
@Component({
selector: "app-example",
templateUrl: "./example.component.html"
})
export class Example extends onDestroy {
private unsubscribe: Subject<void> = new Subject();
// ... some subscriptions:
// observable.pipe(takeUntil(this.unsubscribe)).subscribe(/* do something */)
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
if (this.unsubscribe.closed) {
//subscribed
console.log("unsubscribed");
} else console.log("subscribed");
}
}
并将其登录到“订阅”控制台。
我在所有管道中使用的唯一操作员是“ takeuntil”。
我应该使用'.unsubscribe'而不是“ .complete”?
Subject 'complete' of rxjs is not unsubscribing on complete in Angular.
I am using the 'takeUntil' unsubscription approach.
I have multiple subscriptions in my app and I would like to unsubscribe all of them in 'ngOnDestroy'.
I have created the following logic:
@Component({
selector: "app-example",
templateUrl: "./example.component.html"
})
export class Example extends onDestroy {
private unsubscribe: Subject<void> = new Subject();
// ... some subscriptions:
// observable.pipe(takeUntil(this.unsubscribe)).subscribe(/* do something */)
ngOnDestroy() {
this.unsubscribe.next();
this.unsubscribe.complete();
if (this.unsubscribe.closed) {
//subscribed
console.log("unsubscribed");
} else console.log("subscribed");
}
}
and it logs to the console "subscribed".
the only operator I'm using in all of the pipes is 'takeUntil'.
Should I use '.unsubscribe' instead of '.complete'?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论