繁体   English   中英

如何在 http 请求后取消订阅 Angular 中的 observable 并停止更新?

[英]How to unsubscribe from observable in Angular after http request and stop updating?

当我这样做时:

comments: Comment[] | undefined;
loadComments(){
this.http.get<Comment[]>(`${this.apiServerUrl}`, options).subscribe(
      (response: Comment[]) => this.comments = response
    );
}

如何取消订阅,并在 html 文件 static 中制作我的 output? 问题是,在我的项目中,我有很多订阅,当我启动我的应用程序时,它会吃掉我的内存。

实际上,您不必取消订阅 http observables。 一旦响应到达,它就完成了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM