路线在Angular 2中更改时的结束时间间隔 [英] End interval when route changes in Angular 2
本文介绍了路线在Angular 2中更改时的结束时间间隔的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在路由器插座内的Angular 2组件中启动计时器.
I start a timer in an Angular 2 component which is inside a router outlet.
setInterval(() => {
...
}, 10000);
当我离开嵌入组件的路由时,计时器不会退出.我该如何实现?
When I leave the route in which the component is embedded the timer isn't quit. How can I achieve that?
推荐答案
这应该做到:
routerOnActivate() {
this.timer = setInterval(()=>{
...
}, 10000);
}
routerOnDeactivate() {
clearInterval(this.timer);
}
这篇关于路线在Angular 2中更改时的结束时间间隔的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文