订阅组件中的可观察对象时,您几乎总是安排在组件销毁时退订. When subscribing to an observable in a component, you almost always arrange to unsubscribe when the component is destroyed.有一些不需要观察的例外观察点.可观察到的ActivatedRoute除外.There are a few exceptional observables where this is not necessary. The ActivatedRoute observables are among the exceptions. ActivatedRoute及其可观察物与路由器绝缘本身.当路由组件不再存在时,它会销毁它需要,注入的ActivatedRoute随之死亡.The ActivatedRoute and its observables are insulated from the Router itself. The Router destroys a routed component when it is no longer needed and the injected ActivatedRoute dies with it.随时可以退订.它是无害的,从不坏练习.Feel free to unsubscribe anyway. It is harmless and never a bad practice. 这篇关于Angular有必要退订this.activatedRoute订阅的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 09-21 19:49