Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ionic Action Sheet (ActionSheet)

ionic Action Sheet (ActionSheet)

The Action Sheet (ActionSheet) pops up a box to let users choose an option.

Very dangerous options are highlighted in red for immediate recognition. You can make it disappear by tapping the Cancel button or tapping an empty area.


Example

HTML Code







    

        

            

Action Sheet

JavaScript Code

To trigger the action sheet in code, you need to use the $ionicActionSheet service in your Angular controller:



angular.module('starter', ['ionic'])



.run(function($ionicPlatform) {

  $ionicPlatform.ready(function() {

    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard

    // for form inputs)

    if(window.cordova && window.cordova.plugins.Keyboard) {

      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

    }

    if(window.StatusBar) {

      StatusBar.styleDefault();

    }

  });

})



.controller( 'actionsheetCtl',['$scope','$ionicActionSheet','$timeout' ,function($scope,$ionicActionSheet,$timeout){

    $scope.show = function() {



        var hideSheet = $ionicActionSheet.show({

            buttons: [

              { text: 'Share This' },

              { text: 'Move' }

            ],

            destructiveText: 'Delete',

            titleText: 'Modify your album',

            cancelText: 'Cancel',

            cancel: function() {

                 // add cancel code..

               },

            buttonClicked: function(index) {

              return true;

            }

        });



        $timeout(function() {

            hideSheet();

        }, 2000);



    };  

}])

The running result is shown below: