[英]How to unsubscribe from observable in Angular after http request and stop updating?
When I do this:当我这样做时:
comments: Comment[] | undefined;
loadComments(){
this.http.get<Comment[]>(`${this.apiServerUrl}`, options).subscribe(
(response: Comment[]) => this.comments = response
);
}
How can I unsubscribe on this, and made my output in html file static?如何取消订阅,并在 html 文件 static 中制作我的 output? Problem is that, in my project, I have a lot of subscribes and when I start my app, it eat my RAM so hard.
问题是,在我的项目中,我有很多订阅,当我启动我的应用程序时,它会吃掉我的内存。
Actually you do not have to unsubscribe from http observables.实际上,您不必取消订阅 http observables。 It completes as soon as response arrives.
一旦响应到达,它就完成了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.