取消routeChange一个AngularJS $超时 [英] Cancel a AngularJS $timeout on routeChange

查看:148
本文介绍了取消routeChange一个AngularJS $超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的应用程序特定的页面,我认为做一个服务器调用来更新设置的时间间隔的信息。
我在一个偶然的问题,虽然。我想取消我的$超时当用户从有问题的页面导航走,这样应用程序不会尝试的东西,是不存在了工作。

On a specific page in my application I think of doing a server-call to update information on a set interval. I stumbled upon a problem though. I want to cancel my $timeout when a user navigates away from the page in question so that the application doesn't try to work with stuff that isn't there anymore.

如何解决这个任何想法?

Any ideas on how to work around this?

推荐答案

使用 $ timeout.cancel 是这样的:

yourTimer = $timeout(function() { /* ... */ }, 5000);
$timeout.cancel(yourTimer);

参考

这篇关于取消routeChange一个AngularJS $超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆