AngularJs-destroy事件

    $scope.$on("$destroy", function() {
            //清除配置,不然scroll会重复请求
        })

在Controller中监听$destory事件,这个事件会在页面发生跳转的时候触发。

在页面跳转之后,这个页面监听的一些全局事件,比如window.scroll事件在下一页scroll的时候还会继续被触发

在这个事件的回调中,清除当前页面的监听或者一些参数保证下面的页面不会再触发当前页面的事件回调

【举个栗子】

controller:'UserInfo'
//验证必填信息
$scope.$on("$destroy", function() {
if(!$scope.currentUser.telephone || !$scope.currentUser.address){
layer.alert("请将个人信息补充完整");
$location.path("userInfo");
}
})

相关文章:

  • 2021-11-20
  • 2021-12-31
  • 2021-09-04
  • 2021-07-13
  • 2021-07-29
  • 2021-11-24
  • 2021-10-21
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-01-29
相关资源
相似解决方案