ionic 教程
1. ionic 教程 2. ionic 安装 3. ionic 创建 APP 4. ionic 头部与底部 5. ionic 按钮 6. ionic 列表 7. ionic 卡片 8. ionic 表单和输入框 9. ionic toggle(切换开关) 10. ionic checkbox 11. ionic 单选框 12. ionic range 13. ionic select 14. ionic tab(选项卡) 15. ionic 网格(Grid) 16. ionic 颜色 17. ionic 上拉菜单(ActionSheet) 18. ionic 背景层 19. ionic 下拉刷新 20. ionic 复选框 21. ionic 单选框操作 22. ionic 切换开关操作 23. ionic 手势事件 24. ionic 头部和底部 25. ionic 列表操作 26. ionic 加载动作 27. ionic 模态窗口 28. ionic 导航 29. ionic 平台 30. ionic 浮动框 31. ionic 对话框 32. ionic 滚动条 33. ionic 侧栏菜单 34. ionic 滑动框 35. ionic 加载动画 36. ionic 选项卡栏操作

ionic 浮动框

ionic 浮动框


$ionicPopover

$ionicPopover 是一个可以浮在app内容上的一个视图框。

可以实现以下功能点:

  • 在当前页面显示更多信息。
  • 选择一些工具或配置。
  • 在页面提供一个操作列表。

方法


fromTemplate(templateString, options)

或

fromTemplateUrl(templateUrl, options)

参数说明:

templateString: 模板字符串。

templateUrl: 载入的模板 URL。

options: 初始化选项。

实例

HTML 代码部分

<p> <button ng-click="openPopover($event)">打开浮动框</button> </p> <script id="my-popover.html" type="text/ng-template"> <ion-popover-view> <ion-header-bar> <h1 class="title">我的浮动框标题</h1> </ion-header-bar> <ion-content> Hello! </ion-content> </ion-popover-view> </script>

fromTemplateUrl 方法

angular.module('ionicApp', ['ionic']) .controller( 'AppCtrl',['$scope','$ionicPopover','$timeout',function($scope,$ionicPopover,$timeout){ $scope.popover = $ionicPopover.fromTemplateUrl('my-popover.html', { scope: $scope }); // .fromTemplateUrl() 方法 $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(); }; // 清除浮动框 $scope.$on('$destroy', function() { $scope.popover.remove(); }); // 在隐藏浮动框后执行 $scope.$on('popover.hidden', function() { // 执行代码 }); // 移除浮动框后执行 $scope.$on('popover.removed', function() { // 执行代码 }); }])

55面试教程网 »

我们也可以把模板当作一个字符串,使用 .fromTemplate() 方法来实现弹框:

fromTemplate 方法

angular.module('ionicApp', ['ionic']) .controller( 'AppCtrl',['$scope','$ionicPopover','$timeout',function($scope,$ionicPopover,$timeout){ $scope.popover = $ionicPopover.fromTemplateUrl('my-popover.html', { scope: $scope }); // .fromTemplate() 方法 var template = '<ion-popover-view><ion-header-bar> <h1 class="title">我的浮动框标题</h1> </ion-header-bar> <ion-content> Hello! </ion-content></ion-popover-view>'; $scope.popover = $ionicPopover.fromTemplate(template, { scope: $scope }); $scope.openPopover = function($event) { $scope.popover.show($event); }; $scope.closePopover = function() { $scope.popover.hide(); }; // 清除浮动框 $scope.$on('$destroy', function() { $scope.popover.remove(); }); // 在隐藏浮动框后执行 $scope.$on('popover.hidden', function() { // 执行代码 }); // 移除浮动框后执行 $scope.$on('popover.removed', function() { // 执行代码 }); }])

55面试教程网 »