简体   繁体   English

取消routeChange上的AngularJS $超时

[英]Cancel a AngularJS $timeout on routeChange

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. 我希望在用户离开相关页面时取消我的$ timeout,以便应用程序不会尝试使用不再存在的内容。

Any ideas on how to work around this? 关于如何解决这个问题的任何想法?

Use $timeout.cancel like this: 像这样使用$timeout.cancel

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

Reference 参考

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM