这篇文章给大家分享的是有关AngularJS怎么实现页面跳转后自动弹出对话框的内容。小编觉得挺实用的,因此分享给大家做个参考,一起跟随小编过来看看吧。
今天在做任务的时候发现,需要在angularJS中知道什么时候页面加载完成,这样才能进行一些弹出操作,不然页面没有出来就弹出显得很突兀。
下面是解决办法:
$scope.showAlert = function() {
var alertPopup = $ionicPopup.alert({
title: 'Don\'t eat that!',
template: '<h2>It might taste good</h2>'
});
};
$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();
});
感谢各位的阅读!关于“AngularJS怎么实现页面跳转后自动弹出对话框”这篇文章就分享到这里了,希望以上内容可以对大家有一定的帮助,让大家可以学到更多知识,如果觉得文章不错,可以把它分享出去让更多的人看到吧!