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() {
// 執行程式碼
});
}])
我們也可以把模板當作一個字串,使用 .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() {
// 執行程式碼
});
}])