在不重新加载应用程序的情况下清空应用程序中的所有可观察到
当前,在我们的应用中,我们正在使用location.reload作为清除所有以前数据的所有可观察到的方法。
是否还有其他少一些黑客的方法,例如不重新加载整个应用程序或推荐的一些RXJ?
Currently, in our app we are using location.reload as a sure way to clear all observables of any previous data.
Is there any other less hacky way of doing this like without reloading the whole app or some rxjs recommended way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在Angular应用程序中处理可观察到的正确方法是在不再需要的情况下取消订阅。
一般而言,我们订阅了组件内可观察的一个。因此,当您破坏组件时,必须取消订阅订阅,如下所示:
可以观察到可以在整个应用程序中生存下来,而其他人必须尽快取消订阅,但通常在OnInit上订阅并在Ondestroy方法上取消订阅解决大多数问题的好方法。
The correct way to handle observables in an angular application is to unsubscribe when they are no more needed.
Generally speaking we subscribe to an Observable inside a component. So when you destroy the component you must unsubscribe the subscription as follow:
There can be are observables that survive through the whole application lifetime, while others must be unsubscribed as soon as possible, but often subscribing on the onInit and unsubscribing on the onDestroy methods is a good approach to solve most of the problems.
一旦完成责任,请尝试取消订阅订阅的可观察到的可观察。
try to unsubscribe the subscribed observable, Once there responsibility has been completed.