码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2017-07-07 20:18:10      阅读:314      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!