-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
  • 3,277
  • 2
  • 24
  • 35
  • 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
  • 9,389
  • 5
  • 24
  • 48
1

use unsubscribe

this.testInterval.unsubscribe()
Sachila Ranawaka
  • 39,756
  • 7
  • 56
  • 80