ionic中文教程

浏览30414
更新时间2022-04-11

$ionicPopup

ionic 对话框服务允许程序创建、显示弹出窗口。

$ionicPopup 提供了3个方法:alert(), prompt(),以及 confirm() 。

实例

HTML 代码

<body class="padding" ng-controller="PopupCtrl">
	<button class="button button-dark" ng-click="showPopup()">
	  弹窗显示
	</button>
	<button class="button button-primary" ng-click="showConfirm()">
	  确认对话框
	</button>
	<button class="button button-positive" ng-click="showAlert()">
	  警告框
	</button>

	<script id="popup-template.html" type="text/ng-template">
	  <input ng-model="data.wifi" type="text" placeholder="Password">
	</script>
</body>

JavaScript 代码

angular.module('mySuperApp', ['ionic'])
.controller('PopupCtrl',function($scope, $ionicPopup, $timeout) {

 // Triggered on a button click, or some other target
 $scope.showPopup = function() {
   $scope.data = {}

   // 自定义弹窗
   var myPopup = $ionicPopup.show({
     template: '<input type="password" ng-model="data.wifi">',
     title: 'Enter Wi-Fi Password',
     subTitle: 'Please use normal things',
     scope: $scope,
     buttons: [
       { text: 'Cancel' },
       {
         text: '<b>Save</b>',
         type: 'button-positive',
         onTap: function(e) {
           if (!$scope.data.wifi) {
             // 不允许用户关闭,除非输入 wifi 密码
             e.preventDefault();
           } else {
             return $scope.data.wifi;
           }
         }
       },
     ]
   });
   myPopup.then(function(res) {
     console.log('Tapped!', res);
   });
   $timeout(function() {
      myPopup.close(); // 3秒后关闭弹窗
   }, 3000);
  };
   //  confirm 对话框
   $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');
       }
     });
   };

   //  alert(警告) 对话框
   $scope.showAlert = function() {
     var alertPopup = $ionicPopup.alert({
       title: 'Don\'t eat that!',
       template: 'It might taste good'
     });
     alertPopup.then(function(res) {
       console.log('Thank you for not eating my delicious ice cream cone');
     });
   };
});

相关视频

更多

免费

微信小程序--企业微网站
初级微信小程序--企业微网站

5.4万次学习

收藏

免费

微信小程序开发基础教程
初级微信小程序开发基础教程

6.8万次学习

收藏

免费

微信小程序基础API篇
高级微信小程序基础API篇

3.5万次学习

收藏

免费

微信小程序--微商城
高级微信小程序--微商城

3.9万次学习

收藏

精品课程

更多
前端入门_HTML5
前端入门_HTML5

共29课时

65万人学习

CSS视频教程-玉女心经版
CSS视频教程-玉女心经版

共25课时

41.3万人学习

JavaScript极速入门_玉女心经系列
JavaScript极速入门_玉女心经系列

共43课时

76.8万人学习

独孤九贱(1)_HTML5视频教程
独孤九贱(1)_HTML5视频教程

共25课时

64.2万人学习

独孤九贱(2)_CSS视频教程
独孤九贱(2)_CSS视频教程

共22课时

24.4万人学习

独孤九贱(3)_JavaScript视频教程
独孤九贱(3)_JavaScript视频教程

共28课时

36.3万人学习

独孤九贱(4)_PHP视频教程
独孤九贱(4)_PHP视频教程

共89课时

133.4万人学习

热门下载

更多
phpStudy 2018最新版
phpStudy 2018最新版

集成PHP7,16种组合,超全大合集

下载

VC9 32位
VC9 32位

VC9 32位 phpstudy集成安装环境运行库

下载

VC11 32位
VC11 32位

VC11 32位 phpstudy集成安装环境运行库​

下载

php程序员工具箱完整版
php程序员工具箱完整版

程序员工具箱 v1.0 php集成环境

下载

VC14 32位
VC14 32位

VC14 32位 phpstudy安装环境运行库

下载

SublimeText3汉化版
SublimeText3汉化版

中文版,非常好用

下载

Notepad++ Windows版
Notepad++ Windows版

Notepad++ 8.9.7 Windows版官方安装包,适合 Windows 用户进行代码编辑、文本处理、语法高亮和插件扩展配置。

下载