AngularJs-destroy事件 (页面离开事件)

2021-07-01 09:04

阅读:1322

标签:cat   user   win   scroll   str   layer   class   func   control   

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");
}
})

AngularJs-destroy事件 (页面离开事件)

标签:cat   user   win   scroll   str   layer   class   func   control   

原文地址:http://www.cnblogs.com/miny-simp/p/7133618.html


评论


亲,登录后才可以留言!