How to cancel a subscription in Angular2

后端 未结 8 1534
忘了有多久
忘了有多久 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

提交回复
热议问题