-4

I am facing problem while working with timer in angular 6. I am not able to unsubscribe timer after certain meet condition.

this.testInterval=interval(1000).pipe(
      map(x => this.testSecTime )
    ).subscribe(x => this.reduceTimer());
Volker Siegel
  • 2,989
  • 1
  • 21
  • 32
  • Possible duplicate of https://stackoverflow.com/q/34442693/5468463 – Vega Aug 17 '18 at 11:40
  • Possible duplicate of [How to cancel a subscription in Angular2](https://stackoverflow.com/questions/34442693/how-to-cancel-a-subscription-in-angular2) – Makyen Aug 18 '18 at 23:56

2 Answers2

2

use unsubscribe for this.

if page destoy

ngOnDestroy() {
    this.testInterval.unsubscribe()
}

OR

for any condition

this.testInterval.unsubscribe()
Krishna Rathore
  • 8,604
  • 3
  • 23
  • 46
1

use unsubscribe

this.testInterval.unsubscribe()
Sachila Ranawaka
  • 31,266
  • 5
  • 51
  • 75