Popover

$ionicPopover, 参看接着讲解的 ionicPopover 控制器。这个控件和上篇中讲到的ionicModal 内容基本一致。
popover是浮动在用户app内容之上的view视图,很方便的用来展示或收集用户信息,主要用于:

展示当前view视图的更多信息
选择一个常用的工具或配置
展现一个app视图中的动作列表
把要显示在popover中的内容放在元素中即可。
用法:

12345678910111213141516171819202122232425262728293031323334353637383940
<p>  <button ng-click="openPopover($event)">Open Popover</button></p><script id="my-popover.html" type="text/ng-template"> <ion-popover-view> <ion-header-bar> <h1 class="title">My Popover Title</h1> </ion-header-bar> <ion-content> Hello! </ion-content> </ion-popover-view></script>

angular.module('testApp', ['ionic']).controller('MyController', function($scope, $ionicPopover) { $ionicPopover.fromTemplateUrl('my-popover.html', { scope: $scope, }).then(function(popover) { $scope.popover = popover; }); $scope.openPopover = function($event) { $scope.popover.show($event); }; $scope.closePopover = function() { $scope.popover.hide(); }; //Cleanup the popover when we're done with it! $scope.$on('$destroy', function() { $scope.popover.remove(); }); // Execute action on hide popover $scope.$on('popover.hidden', function() { // Execute action }); // Execute action on remove popover $scope.$on('popover.removed', function() { // Execute action });});

API 方法:

1234567
fromTemplate(templateString, options), 返回ionicPopover的控制器实例----templateString, 类型string,modal中显示的内容。----options,类型object,传递给 $ionicPopover 初始化方法的参数-------------------------------------------fromTemplateUrl(templateUrl, options),返回 ionicPopover 的控制器实例中用到的promise对象----templateString, 类型string,modal中显示的内容url。----options,类型object,传递给 $ionicPopover 初始化方法的参数

ionicPopover

由$ionicPopover 服务调用,当你不需要popover 的时候,要及时调用remove()方法以避免发生内存泄漏。
注意:popover 会从它自身的scope中广播’popover.shown’, ‘popover.hidden’, 和’popover.removed’事件,把这个作为传递事件参数的一部分。移除popover时会调用popover.removed 和 popover.hidden 这两个事件。

方法:

123456789101112
initialize(options), 创建一个新的modal控制器实例----options,类型object,可选值:-------------{object=} 父scope,默认在$rootScope下创建独立的scope-------------{string=} 显示或隐藏的动画效果. 默认是'slide-in-up'-------------{boolean=} 是否让popover的第一个输入获得焦点,默认是false.-------------{boolean=} 点击背景的是否自动关闭popover,默认是 true-------------{boolean=} 是否可以使用手机的硬件返回按钮关闭popover,默认: true.show($event),显示popover,返回popover 显示后的promise对象------$event,这个popover对齐的event或target元素hide(), 隐藏popover,返回popover 隐藏后的promise对象remove(),从dom中移除popover 实例,并clean,返回popover 移除后的promise对象isShown(), 返回boolean,表示当前popover 是否显示

Popup

ionic popup服务允许通过程序创建一个popup弹出的窗口,需要用户交互才可以继续。
popup支持原生的 alert(),prompt(),confirm() 这些弹出窗口,也支持可定制内容和样式的弹出框。
popup中的input可以增加autofocus属性,这样当弹出对话框时,会自动是这个input获得焦点。

用法:

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
angular.module('mySuperApp', ['ionic']).controller('PopupCtrl',function($scope, $ionicPopup, $timeout) {// Triggered on a button click, or some other target$scope.showPopup = function() { $scope.data = {} // An elaborate, custom popup 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) { //don't allow the user to close unless he enters wifi password e.preventDefault(); } else { return $scope.data.wifi; } } }, ] }); myPopup.then(function(res) { console.log('Tapped!', res); }); $timeout(function() { myPopup.close(); //close the popup after 3 seconds for some reason }, 3000); }; // A confirm dialog $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'); } }); }; // An alert dialog $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'); }); };});

API 方法:

show(options), 显示一个复杂的popup弹出框。
复杂的弹出框,可以设置一个buttons数组,里面每个button可以设置text属性,type属性和onTap事件,而系统默认在点击按钮时,会关闭对话框并返回结果到promise对象中,如果你不想关闭对话框,可以在onTap事件函数中调用event.preventDefault()。返回一个promise对象,该对象有个close方法,可以在程序中调用这个方法来关闭弹出框。
—-options, 类型是object,参考示例如下:

12345678910111213141516171819202122
{  title: '', // String. The title of the popup.  subTitle: '', // String (optional). The sub-title of the popup. template: '', // String (optional). The html template to place in the popup body. templateUrl: '', // String (optional). The URL of an html template to place in the popup body. scope: null, // Scope (optional). A scope to link to the popup content. buttons: [{ //Array[Object] (optional). Buttons to place in the popup footer. text: 'Cancel', type: 'button-default', onTap: function(e) { // e.preventDefault() will stop the popup from closing when tapped. e.preventDefault(); } }, { text: 'OK', type: 'button-positive', onTap: function(e) { // Returning a value will cause the promise to resolve with the given value. return scope.data.response; } }]}

alert(options),警告弹出框,显示一段信息,和一个按钮,点击按钮可以关闭弹出框。返回一个promise对象,该对象有个close方法,可以在程序中调用这个方法来关闭弹出框。
——options,类型object,配置弹出框的参数。

12345678
{  title: '', // String. The title of the popup. subTitle: '', // String (optional). The sub-title of the popup. template: '', // String (optional). The html template to place in the popup body. templateUrl: '', // String (optional). The URL of an html template to place in the popup body. okText: '', // String (default: 'OK'). The text of the OK button. okType: '', // String (default: 'button-positive'). The type of the OK button.}

confirm(options),弹出一个comfirm对话框,点击ok按钮返回true,点击cancel返回false的promise对象。返回一个promise对象,该对象有个close方法,可以在程序中调用这个方法来关闭弹出框。
——options,类型object,显示confirm对话框的参数。例子:

12345678910
{  title: '', // String. The title of the popup. subTitle: '', // String (optional). The sub-title of the popup. template: '', // String (optional). The html template to place in the popup body. templateUrl: '', // String (optional). The URL of an html template to place in the popup body. cancelText: '', // String (default: 'Cancel'). The text of the Cancel button. cancelType: '', // String (default: 'button-default'). The type of the Cancel button. okText: '', // String (default: 'OK'). The text of the OK button. okType: '', // String (default: 'button-positive'). The type of the OK button.}

prompt(options),显示一个带有输入框,ok按钮,cancel按钮的对话框。点击ok时,返回的promise对象中包含输入的值,点击cancel时,值为undefined。返回的promise对象有个close方法,可以在程序中调用这个方法来关闭弹出框。使用例子:

12345678
$ionicPopup.prompt({   title: 'Password Check', template: 'Enter your secret password', inputType: 'password', inputPlaceholder: 'Your password' }).then(function(res) { console.log('Your password is', res); });

—— options, 类型object,配置对话框参数。示例:

123456789101112
{  title: '', // String. The title of the popup. subTitle: '', // String (optional). The sub-title of the popup. template: '', // String (optional). The html template to place in the popup body. templateUrl: '', // String (optional). The URL of an html template to place in the popup body. inputType: // String (default: 'text'). The type of input to use inputPlaceholder: // String (default: ''). A placeholder to use for the input. cancelText: // String (default: 'Cancel'. The text of the Cancel button. cancelType: // String (default: 'button-default'). The type of the Cancel button. okText: // String (default: 'OK'). The text of the OK button. okType: // String (default: 'button-positive'). The type of the OK button.}

scroll

ion-scroll 创建一个可以容纳所有内容,滚动的容器。

用法:

123
<ion-scroll zooming="true" direction="xy" style="width: 500px; height: 500px"> <div style="width: 5000px; height: 5000px; background: url('https://upload.wikimedia.org/wikipedia/commons/a/ad/Europe_geological_map-en.jpg') repeat"></div> </ion-scroll>

注意:设置scroll box的高度和内部内容的高度很重要,这样才可以让滚动区域随意滚动显示。
API 参数:

12345678910111213
delegate-handle(optional), string,控制这个scroll view的委托实例$ionicScrollDelegatedirection(optional),string,滚动的方向. 'x' or 'y' or 'xy'. 默认是 'y'.属性:locking(可选),类型boolean,是否锁定一次只能滚动一个方向属性:padding(可选),类型boolean,是否给content增加padding,iOS默认为true,android默认为false属性:scroll(可选),类型boolean,是否允许滚动内容,默认是true属性:on-scroll,类型:expression,滚动内容时执行的表达式属性:on-refresh,类型:expression,下拉刷新时调用,由ionRefresher 触发。属性:scrollbar-x,类型boolean,是否显示x轴滚动条属性:scrollbar-y,类型boolean,是否显示y轴滚动条属性:zooming,类型boolean,是否支持手势缩放属性:min-zoom,类型integer,最小缩放比例,默认是0.5属性:max-zoom,类型integer,最大缩放比例,默认是3属性:has-bouncing,类型:boolean,是否允许滚动时弹跳超过内容体的边界,ios默认true,Android默认false

ion-infinite-scroll

ionContent 和 ionScroll 中共有的子元素。
ionInfiniteScroll 允许你在用户滚动到内部内容的边缘时调用一个回调函数。
当用户滚动内容距离底部小于distance定义的距离时,会自动调用on-infinite中定义的回调函数,可以加载更多内容,加载完更多内容后,在控制器中需要广播croll.infiniteScrollComplete 事件。使用实例:

12345678910111213141516171819202122
<ion-content ng-controller="MyController">  <ion-list>  .... .... </ion-list> <ion-infinite-scroll on-infinite="loadMore()" distance="1%"> </ion-infinite-scroll></ion-content>function MyController($scope, $http) { $scope.items = []; $scope.loadMore = function() { $http.get('/more-items').success(function(items) { useItems(items); $scope.$broadcast('scroll.infiniteScrollComplete'); }); }; $scope.$on('$stateChangeSuccess', function() { $scope.loadMore(); });}

当没有更多内容加载时,停止infinite scroll的方法是使用ng-if指令

12345
<ion-infinite-scroll  ng-if="moreDataCanBeLoaded()"  icon="ion-loading-c" on-infinite="loadMoreData()"></ion-infinite-scroll>

API 参数:

12345
on-infinite, 类型expression,当滚动到底部时候的调用函数distance(可选),类型string,定义距离底部多少时调用on-infinite定义的表达式,默认是:1%icon(可选),类型string,定义加载过程中显示的图标,默认是‘ion-loading-d'

$ionicScrollDelegate

转载于:https://www.cnblogs.com/1992825-Amelia/p/4847216.html

ionic popover、popu、scroll相关推荐

  1. [译] React Native vs. Cordova、PhoneGap、Ionic,等等

    原文链接: learnreact.design/2018/02/14/- 喜欢理由: 文笔生动 通俗易懂 特别鸣谢: 原作者 Linton Ye 的倾情校对 系列博客: 用通俗的语言和涂鸦来解释 Re ...

  2. JavaScript-client、offset、scroll、定时器

    client offset scroll client.offset.scroll系列 他们的作用主要与计算盒模型,盒子的偏移量和滚动有关 clientTop 内容区域到边框顶部的距离, 说白了, 就 ...

  3. html5+、ReactNative、Weex、Ionic之间的区别、(配置java、python、Android环境)、ReactNative(react-native-cli)、yarn、Weex

    html5+.ReactNative.Weex.Ionic之间的区别: html5+和Ionic: 在开发原理上基本相同,都是需要先开发出一个完整的网站,再通过html5+或Ionic提供的打包技术对 ...

  4. 网页特效offset、client、scroll系列属性的作用

    元素偏移量 offset 系列 可以动态的得到元素的位置(偏移).大小等 获得元素距离带有定位父元素的位置 获得元素自身的大小(宽度高度) 注意:返回的数字都不带单位 offset系列属性 作用 el ...

  5. js中offset、client、scroll【总结】

    offset系列 offset动态的得到目标元素的位置(偏移)大小等 offset系列常用属性 offset系列属性 作用 element.offsetParent 返回作为该元素带有定位的父级元素 ...

  6. app端前端框架对比 - Mui与ionic、Cordova 、Weex、React Native对比

    1.1.1.介绍: mui是最接近原生App体验的前端框架. 极小:100k的js文件,60k的css文件.原生编写,不依赖任何三方框架 极强:xcode和Android studio里所有原生控件都 ...

  7. ElasticSearch 的 from+size、scroll、scroll-scan、sliced scroll-sacn、search after

    参考文章: 使用scroll实现Elasticsearch数据遍历和深度分页 Elasticsearch 5.x 源码分析(3)from size, scroll 和 search after Ela ...

  8. Ionic实现微信、qq、微博分享

    Ionic实现微信.qq.微博分享 这篇文档针对的是ionic1.ionic虽然ionic版本不同,但大体的思想还是相同的. Ionic要想实现微信.qq.微博的分享,第一步必须先申请相应的应用权限. ...

  9. 三大家族scroll、offset、client

    三大家族scroll.offset.client JS的三大家族主要是Offset.Scroll.Client,通过对三大家族不同属性的灵活使用,我们可以模拟出很多炫酷的JS动画,增强界面的视觉感染力 ...

最新文章

  1. java 抽象类 模板_Java抽象类的构造模板模式用法示例
  2. ASP.NET Page执行顺序如:OnPreInit()、OnInit()
  3. 数组中只出现一次的数字+第一个只出现一次的字符
  4. Rest之一-什么是REST?以及RESTful的实现
  5. 系统页面升级系统中_中交出行通勤班线系统全新升级!页面亮点功能说明
  6. Linux: centOS6.5 RabbitMQ
  7. Petya and Staircases CF212div.2B
  8. OpenCV2:Mat介绍及常见用法
  9. 在layui表格中插入时间插件
  10. Android8.0.0的BUG Only fullscreen opaque activities can request orientation
  11. html5 判断手机横竖屏,移动端判断横竖屏的5种解决方案
  12. 使用Matlab对大地测量学中的大地坐标和大地空间直角坐标进行相互转换
  13. 神经网络编程的34个案例,人工神经网络编程内容
  14. Collapse search results
  15. 商业智慧:创造奇迹的信件
  16. 7-2 寻找大富翁 (34 分)
  17. pytho语法总结(1):基础知识,列表介绍,列表操作
  18. matlab求两向量夹角_【求精干货】高中数学知识点总结归纳高一学生必须掌握
  19. 08.零售类公司分析•上
  20. STM32F407ZGT6最小系统原理图和PCB

热门文章

  1. QT不规则形状的按钮的实现
  2. 南京大学计算机 吴迪,吴迪 教授
  3. 厦门大学2020计算机调剂,厦门大学2020考研招调剂生,57个名额,截止到5月1日
  4. UCloud可用区的设计理念及功能图文详解
  5. 古文观止卷七_兰亭集序_王羲之
  6. 拒绝“累丑”,告别加班,一键读取Excel表格数据自动录入至网页
  7. VMware仅主机模式下无法上网问题
  8. 【阿里云Grafana】数据可观测云监控大盘服务
  9. 如何查询移动物联网卡ICCID号码?
  10. linux通过nfs挂载根文件系统报错:VFS: Unable to mount root fs via NFS, trying floppy