How to unsubscribe/stop Observable?

前端 未结 3 1509
北海茫月
北海茫月 2020-12-17 01:30

I use the following code for timer:

export class TimerService {
  private ticks: number = 0;
  private seconds: number = 0;
  private timer;

  constructor(s         


        
3条回答
  •  南方客
    南方客 (楼主)
    2020-12-17 02:18

    The best way is to unsubscribe when instance is destroyed.

    ngOnDestroy() {
     this.sub.unsubscribe();
    }
    

提交回复
热议问题