angular - 如何在角度 6 中取消订阅计时器?
问题描述
我在使用角度 6 中的计时器时遇到问题。在某些满足条件后,我无法取消订阅计时器。
this.testInterval=interval(1000).pipe(
map(x => this.testSecTime )
).subscribe(x => this.reduceTimer());
解决方案
用于unsubscribe
此。
如果页面破坏
ngOnDestroy() {
this.testInterval.unsubscribe()
}
或者
对于任何条件
this.testInterval.unsubscribe()
推荐阅读
- react-hooks - 将回调传递给自定义反应钩子
- python-3.x - 是否可以使用 Python tarfile 读取并附加到 tar
- anaconda - Anaconda 安装卡在 - '设置包缓存'
- flutter - 无法使用 Quckblox 和 Flutter 接收消息和传入事件
- javascript - 如何展平不同对象的嵌套数组但仅从现有属性名称中获取值?
- bash - 代码没有列出两个输入之间的所有偶数
- javascript - Html 和 Javascript:结合按钮和 js 功能代码
- reactjs - 根据从 reactjs 中的下拉选项中选择来渲染对象
- r - R:更改文件夹中所有文件的文本
- windows-server-2008 - PowerShell 5.0 PathTooLongException 错误