Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我$timeout经常在我的 angularjs 应用程序中的一个页面上更新信息。我想取消$timeout当用户离开此页面时。有没有一种简单的方法可以做到这一点?
$timeout
好的,我在挖掘后找到了解决方案:
$scope.$on('$destroy', function() { $timeout.cancel(timeout); });
或者对于 Angular 1.5 中的新组件语法:
this.$onDestroy = function() { if (timeout) { $timeout.cancel(timeout); } }