我有一个 Controller ,它通过一个可观察对象加载大量数据。如果我离开该路线并且 View 从页面中删除,我如何在我的 Controller 中得到通知,以便我可以停止 Controller 中的数据加载?
我基本上想要一个在不再需要 Controller 时触发的停用功能或清理功能。
最佳答案
您可以监听 $destroy
事件,并执行一些清理/拆卸操作:
module.controller("SomeController", function($scope) {
$scope.$on("$destroy", function() {
// clean up here
});
});
资源:
关于javascript - AngularJs - 如何在导航到新路线时清理 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35344656/