[英]How to stop previous page controller from working when changing page?
I am applying pagination on scroll on every page. 我在每个页面的滚动上应用分页。 Everytime I change page, pagination function reloads from previous page as well.
每次更改页面时,分页功能也会从上一页重新加载。 This way as I traverse different pages , pagination functions get called everytime from all those page controllers.
这样,当我遍历不同页面时,所有这些页面控制器都会每次调用分页功能。 How can I stop previous page controller functions from working.
如何停止以前的页面控制器功能正常工作。
Pagination logic is that on window scroll to bottom, trigger pagination function & the page gets more content. 分页逻辑是在窗口上滚动到底部时,触发分页功能,页面会获得更多内容。
Here is the code: 这是代码:
angular.element($window).bind("scroll",function() {
var windowHeight = "innerHeight" in window ? window.innerHeight: document.documentElement.offsetHeight;
var body = document.body,
html = document.documentElement;
var docHeight = Math.max(body.scrollHeight,body.offsetHeight, html.clientHeight,html.scrollHeight, html.offsetHeight);
windowBottom = windowHeight + window.pageYOffset;
if (windowBottom >= docHeight) {
if($scope.moredataleft==true && $scope.loadingLoader==false)
{
if($scope.drugnameScroll==true&&$scope.drugSearchScroll==false)
{
if($scope.page==0)
{
$scope.page=2;
}
else{
$scope.page=$scope.page+1;
}
$scope.pagination();
}
}
}
});
I got the solution using $destroy event in angularjs. 我在angularjs中使用$ destroy事件获得了解决方案。 I had to unbind the scroll event handler as suggested by @Nikos in comment to stop its working when controller is destroyed.
我必须取消绑定@Nikos在注释中建议的滚动事件处理程序,以在控制器被销毁时停止其工作。
$scope.$on('$destroy',function(){
angular.element($window).unbind("scroll");
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.