今天在做任務的時候發現,需要在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之后廢除了?但是我使用老版本是可以的。還要多學習其他方法捏..
聲明:本網頁內容旨在傳播知識,若有侵權等問題請及時與本網聯系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com