Difference between .unsubscribe to .take(1)

后端 未结 2 1910
栀梦
栀梦 2020-12-01 02:14

I wonder, if there is any difference in performance between using .take(1) and .unsubscribe when unsubscribe is used right after the s

2条回答
  •  长情又很酷
    2020-12-01 02:36

    Just keep in mind that take(1) still doesn’t unsubscribe when component is being destroyed. The subscription remains active until first value is emitted no matter if component is active or destroyed. So if we do something more crazy, like accessing the DOM, in our subscription — we might end up with an error in the console. https://medium.com/angular-in-depth/the-best-way-to-unsubscribe-rxjs-observable-in-the-angular-applications-d8f9aa42f6a0

提交回复
热议问题