Angular定时器因组件销毁而闪烁
创始人
2024-10-24 12:33:11
0

在组件销毁时,应该取消相关的定时器。可以在Angular生命周期钩子函数ngOnDestroy()中取消定时器。

示例代码:

import { Component, OnInit, OnDestroy } from '@angular/core';

@Component({ selector: 'app-timer', templateUrl: './timer.component.html', styleUrls: ['./timer.component.css'] }) export class TimerComponent implements OnInit, OnDestroy {

timer: any; count: number = 0;

constructor() { }

ngOnInit() { this.timer = setInterval(() => { this.count++; }, 1000); }

ngOnDestroy() { clearInterval(this.timer); }

}

相关内容

热门资讯

epoker免费透视脚本!hh... epoker免费透视脚本!hhpoker真的假的(透视)app-本来曝光存在有挂1、下载好epoke...
透视开挂!wepokerplu... 透视开挂!wepokerplus万能挂(透视)wpk透视工作室,教程总结(有挂透视)-哔哩哔哩1.w...
wpk辅助插件!wepoker... wpk辅助插件!wepoker辅助透视软件(透视)神器-真是辅助真的是有挂运wepoker辅助透视软...
透视曝光!hhpoker是真的... 透视曝光!hhpoker是真的吗(透视)hhpoker辅助挂,教程练习(有挂工具)-哔哩哔哩1)hh...
hhpoker德州透视挂!哈糖... hhpoker德州透视挂!哈糖大菠萝有没有挂(透视)神器-一贯普及存在有挂1、哈糖大菠萝有没有挂免费...
透视揭露!aapoker如何设... 透视揭露!aapoker如何设置胜率(透视)wepoker辅助器最新版本更新内容,教程烘培(存在有挂...
wepoker辅助软件价格!德... wepoker辅助软件价格!德普之星透视辅助插件(透视)攻略-真是必备存在有挂暗藏猫腻,小编详细说明...
透视科普!wepoker透视方... 透视科普!wepoker透视方法(透视)hhpoker辅助,教程手筋(新版有挂)-哔哩哔哩一、wep...
wepokerplus开挂!p... wepokerplus开挂!pokemmo手机脚本(透视)脚本-其实教你是真的挂1、点击下载安装,p...
透视分享!wepoker手机版... 透视分享!wepoker手机版辅助(透视)wepoker看底牌,教程绝活(了解有挂)-哔哩哔哩1、点...