今天在做任務(wù)的時(shí)候發(fā)現(xiàn),需要在angularJS中知道什么時(shí)候頁(yè)面加載完成,這樣才能進(jìn)行一些彈出操作,不然頁(yè)面沒(méi)有出來(lái)就彈出顯得很突兀。
下面是解決辦法:
$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();     }); 運(yùn)行效果:

能夠隱約的看到了后面的頁(yè)面了,說(shuō)明先進(jìn)行的頁(yè)面加載,之后才進(jìn)行的彈出。
PS:下面看下angularjs頁(yè)面加載后自動(dòng)彈窗
首先在控制器內(nèi)寫好一個(gè)彈窗,我用的是ionic的默認(rèn)提示對(duì)話框
// 一個(gè)確認(rèn)對(duì)話框  $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');    }   });  };然后在控制器內(nèi)加入$viewContentLoaded事件
$scope.$watch('$viewContentLoaded', function() {     $scope.showConfirm();   });  在網(wǎng)上看有人說(shuō)在官方的API里面沒(méi)有看到viewContentLoaded,可能Angular2之后廢除了?但是我使用老版本是可以的。還要多學(xué)習(xí)其他方法捏..
新聞熱點(diǎn)
疑難解答
圖片精選
網(wǎng)友關(guān)注