Ionic 的 ActionSheet 是一種從底部彈出的選單,常用於提供分享、刪除、移動等快速操作。本文示範如何在 Angular 控制器中觸發 ActionSheet。
<body ng-app="starter" ng-controller="actionsheetCtl">
<ion-pane>
<ion-content>
<h2 ng-click="show()">Action Sheet</h2>
</ion-content>
</ion-pane>
</body>
在 Angular 控制器中注入 $ionicActionSheet 與 $timeout,即可顯示並自動關閉選單。
.controller("actionsheetCtl", [
"$scope",
"$ionicActionSheet",
"$timeout",
function ($scope, $ionicActionSheet, $timeout) {
$scope.show = function () {
var hideSheet = $ionicActionSheet.show({
buttons: [
{ text: "<b>Share</b> This" },
{ text: "Move" }
],
destructiveText: "Delete",
titleText: "Modify your album",
cancelText: "Cancel",
cancel: function () {
// 可加入取消時的處理
},
buttonClicked: function (index) {
return true;
}
});
$timeout(function () {
hideSheet();
}, 2000);
};
}
]);

buttons 可定義一般選項,destructiveText 通常用來標示危險操作,例如刪除。cancelText 則是取消按鈕文字。若要讓選單在指定時間後自動關閉,可使用 $timeout 呼叫 hideSheet。
透過 ActionSheet,Ionic 應用可以快速提供清楚且易於操作的行動選單。