AngularJS实现页面跳转后自动弹出对话框实例代码

Hanna ·
更新时间:2024-09-21
· 668 次阅读

今天在做任务的时候发现,需要在angularJS中知道什么时候页面加载完成,这样才能进行一些弹出操作,不然页面没有出来就弹出显得很突兀。

下面是解决办法:

$scope.showAlert = function() { var alertPopup = $ionicPopup.alert({ title: 'Don\'t eat that!', template: '<h1>It might taste good</h1>' }); }; $scope.$watch('$viewContentLoaded', function() { $scope.showAlert(); });

运行效果:

能够隐约的看到了后面的页面了,说明先进行的页面加载,之后才进行的弹出。

PS:下面看下angularjs页面加载后自动弹窗

首先在控制器内写好一个弹窗,我用的是ionic的默认提示对话框

// 一个确认对话框 $scope.showConfirm = function() { var confirmPopup = $ionicPopup.confirm({ title: 'Consume Ice Cream', template: 'Are you sure you want to eat this ice cream?' }); confirmPopup.then(function(res) { if(res) { console.log('You are sure'); } else { console.log('You are not sure'); } }); };

然后在控制器内加入$viewContentLoaded事件

$scope.$watch('$viewContentLoaded', function() { $scope.showConfirm(); });  

在网上看有人说在官方的API里面没有看到viewContentLoaded,可能Angular2之后废除了?但是我使用老版本是可以的。还要多学习其他方法捏..



页面跳转 自动 AngularJS 弹出对话框

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章