Cancel a AngularJS $timeout on routeChange

谁说胖子不能爱 提交于 2019-12-18 13:53:11

问题


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?


回答1:


Use $timeout.cancel like this:

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

Reference



来源:https://stackoverflow.com/questions/14897608/cancel-a-angularjs-timeout-on-routechange

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!