【问题标题】:How to unsubscribe timer in angular 6?如何取消订阅 Angular 6 中的计时器?
【发布时间】:2018-08-17 11:18:34
【问题描述】:

我在使用 Angular 6 中的计时器时遇到问题。在某些满足条件后,我无法取消订阅计时器。

this.testInterval=interval(1000).pipe(
      map(x => this.testSecTime )
    ).subscribe(x => this.reduceTimer());

【问题讨论】:

标签: angular


【解决方案1】:

为此使用unsubscribe

如果页面破坏

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

适用于任何情况

this.testInterval.unsubscribe()

【讨论】:

    【解决方案2】:

    使用unsubscribe

    this.testInterval.unsubscribe()
    

    【讨论】:

      猜你喜欢
      • 2019-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 2020-06-16
      • 2023-01-04
      • 2016-07-29
      • 1970-01-01
      相关资源
      最近更新 更多