Tutorialsplane

Ionic Action Sheet


Ionic Action Sheet : Action Sheet is a slide-up pane which enables users to select one option from set of options. You can easily close the Action sheet by clicking on the backdrop or using escape key. Here we are going to explain the method to create Action Sheet in ionic framework with example and demo.


Ionic Action Sheet Example

Here we have created simple button and added event to create Action Sheet when clicked on it.

Ionic Action Sheet

.controller('MainCtrl', function($scope, $ionicActionSheet) { 
// Is Triggered on a button click or on other event.
 $scope.myAcSheet = function() {

   // Show the action sheet
   var hideSheet = $ionicActionSheet.show({
     buttons: [
       { text: 'Btn1- Like This' },
       { text: 'Btn2- Comment' }
     ],
     destructiveText: 'Delete',
     titleText: 'Edit Profile',
     cancelText: 'Cancel',
     cancel: function() {
          // add cancel code..
        },
     buttonClicked: function(index) {
       if(index === 0){
	   // code for button 1 
	   }
	   if(index === 1){
	     // code for button 2
	   }
     }
   });
   
 };

  }, function(err) {
    console.error('ERR', err);
    // err.status will contain the status code
  });

Try it »

In the above example first bind the $ionicActionSheet service with the controller which is required for Action sheet event and then created function $scope.myAcSheet(); which will trigger the pan with specified options.

Now let us call the created function in Html code.

Call Ionic Action Sheet Function

Now call the created function myAcSheet() on button click to trigger the event.

Call Action Sheet In Ioinc

<button type="button" ng-click="myAcSheet()">Action Sheet</button>

If you run the above example it will produce the following output –

Action Sheet Methods

Here are following methods available in Action Sheet –

Ionic Tutorials

Ionic Components

Javascript Components