How to cancel a subscription in Angular2

后端 未结 8 1512
忘了有多久
忘了有多久 2020-11-30 01:37

How does one cancel a subscription in Angular2? RxJS seems to have a dispose method, but I can\'t figure out how to access it. So I have code that has access to an EventEm

相关标签:
8条回答
  • 2020-11-30 02:08
    ngOnDestroy(){
       mySubscription.unsubscribe();
    }
    

    Prefer unsubscribing rxjs unsubscribe's while destroying the component i.e., removing from DOM for avoiding unecessary memory leaks

    0 讨论(0)
  • 2020-11-30 02:10

    Use

    if(mySubscription){
      mySubscription.unsubscribe();
    }
    
    0 讨论(0)
提交回复
热议问题