简体   繁体   English

更改页面时如何停止上一个页面控制器的工作?

[英]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.

相关问题 如何阻止页面重定向到上一个访问的页面? - How to stop page from redirecting to the previous visited page? 如何停止滚动上一页? - How to stop scrolling the previous page? 如何使用ui-router显示错误页面,在从先前状态导航时更改URL? - How to display an error page with ui-router, changing the url when navigating from a previous state? 停止更改页面的属性的href - Stop attribute's href from changing page Angular-引导程序:从控制器更改状态时,使用Angular UI-route的页面导航(“下一步”和“后退”按钮)不起作用 - Angular - Bootstrap: Page navigation (Next and back button) using Angular UI-route not working when changing the state from controller 重定向到上一页不起作用 - Redirect to previous page not working 使用StackNavigator导航到另一页面时销毁当前页面,并停止上一页的所有正在运行的进程 - destroy the current page when navigating to another page using StackNavigator and stop all running process on previous page 使用jQuery对话框时如何阻止基本页面重新加载 - how to stop base page from reloading when using jquery dialog 如何在页面呈现时停止 onClick 呈现? - How do I stop onClick from rendering when the page renders? 加载新数据时如何停止页面滚动 - How to stop page from scrolling when loading new data
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM