[英]Is it necessary to unsubscribe Angular Form statusChanges/valueChanges observable?
By dig into the angular form implementation I found the angular form valueChanges/statusChanges observable are EventEmitters. 通过深入研究角度形式实现,我发现可观察到的角度形式valueChanges / statusChanges是EventEmitters。 Is it necessary to unsubscribe these observables?
是否有必要取消订阅这些观测值? since when use EventEmitters alone we don't unsubscribe?
自从单独使用EventEmitters以来,我们不退订吗?
_initObservables() {
(this as{valueChanges: Observable<any>}).valueChanges = new EventEmitter();
(this as{statusChanges: Observable<any>}).statusChanges = new EventEmitter();
}
It is always a good practice to unsubscribe
if notification is no longer required. 如果不再需要通知,则
unsubscribe
始终是一个好习惯。 Most of the time you can put into ngDestroy()
function not necessarily. 在大多数情况下,您不一定需要将其放入
ngDestroy()
函数。
Is it always required to Unsubscribe ? 是否总是需要退订? No, If
EventEmitter
or Subject
or Observable
in same scope (Component or Service ) where Subscription
is, then no need to destroy since all reference for all will be removed altogether. 否,如果
EventEmitter
或Subject
或Observable
在Subscription
所在的同一范围内(Component或Service),则无需销毁,因为所有参考均将全部删除。
In short, make sure Observable
is unsubscribe
if scope are different for Subscription
and Observable
. 简而言之,如果
Subscription
和Observable
范围不同,请确保Observable
unsubscribe
Subscription
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.