如何在离子页面加载时显示弹出窗口?

时间:2017-02-10 05:57:47

标签: angularjs ionic-framework

我尝试在登录屏幕加载时显示弹出窗口。我如何在离子中做到这一点?我在controllers.js中的当前代码是:

var myPopup = $ionicPopup.show({
template: 'Do you have your one-time mobile password from the website?',
title: 'Credentials Confirmation',
scope: $scope,
buttons: [
  { text: 'Yes' },
  {
    text: 'No',
    type: 'button-positive',
    onTap: function(e) {
      myPopup.close();
      } 
    }
  }
]

});

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码&在其中编写弹出代码。无论是第一次加载还是缓存视图,都会触发此事件。

$scope.$on("$ionicView.enter", function(event, data){
 //popup code here
});

参考网址:http://ionicframework.com/docs/api/directive/ionView/

如果您遇到任何问题,请告诉我

<强>更新

 var myPopup = $ionicPopup.show({
                          template: 'Do you have your one-time mobile password from the website?',
                                       title: 'Credentials Confirmation',
                                       scope: $scope,
                                       buttons: [
                                                 { text: 'Yes' },
                                                 {
                                                 text: 'No',
                                                 type: 'button-positive',
                                                 onTap: function(e) {
                                                   myPopup.close();
                                                 }
                                                 }
                                                 ]
           });