ionicView 生命周期事件不调用处理方法 $ ionicView.loaded $ ionicView.enter

来源:互联网 发布:sg是什么软件 编辑:程序博客网 时间:2024/04/27 23:42

这个问题发现的很早,却一直没有得到解决,今天必须要解决了,查了半天资料终于解决了!

如果在controller中使用$rootScope.$on('$ionicView.enter', function() {});调用,不仅进入该页面会调用,进入其他的页面也会调用,所以是不对的,而且在官方的文档中并没有使用rootScope;

终于在一个帖子中找到了关键:

解决方法


是需要在$stateProvider,路由注册时,把controller也添加进去,否则是不会执行的;

如:

.state('login', {        url: '/login',        templateUrl: 'templates/login.html',        controller:'LoginController'      })

这样就会执行我们在controller中写的生命周期方法了:

 $scope.$on('$ionicView.beforeEnter', function () {console.log('-------beforeEnter-------');}


0 0
原创粉丝点击