ionicActionSheet Undefined

Hello,

I am trying to bring in the ActionSheet and I am following the ActionSheets doc precisely (I am importing $ionicActionSheet into the controller as well) but I keep getting the following error:

undefined is not an object (evaluating '$ionicActionSheet.show')

I also copy and pasted the show function from the ActionSheet docs.

I am relatively new to Ionic and so I am not sure if there is any initialization needed to get this to work, but any help would be greatly appreciated.

Thank you!

hi
try this:
if you don’t use controllerAs so
replace vm.actionSheet to $scope. actionSheet
and call the fund from your view

vm.actionSheet = function() {
    var Sheet = $ionicActionSheet.show({
        buttons: [
          { text: 'btn1' },
          { text: 'btn2 },
          { text: 'btn3' }
        ],
        titleText: 'btns,
        cancelText: 'close',
        cancel: function() {
             // add cancel code..
        },
        buttonClicked: function(index) {
             // btns clicked code..
            return true;
        }
    });
};

if still you having a problem please
copy you’re code here or open codepan

Hi,

Thank you for replying but I’m still running into some issues.

So this is the controller:


.controller('OptimusCtrl', ['$scope', 'Players', 'LineUp', function($scope, Players, LineUp, $ionicActionSheet) {
  Players.all(function(data){
    $scope.allPlayers = $scope.assignLocked(data.data.results);
  })
  $scope.assignLocked = function(array){
    $.each(array,function(key,value){
      value.locked = false;
    })
    return array;
  },
  $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;
      }
    });
  }
}])

Then I call show() with ng-click in the view.  So I don't think I am doing anything crazy here, it's all pretty standard.  But for some reason its still not working.

you need to add $ionicActionSheet
also before function($scope…)
i.e

.controller('OptimusCtrl', ['$scope', 'Players', 'LineUp','$ionicActionSheet', function($scope, Players, LineUp, $ionicActionSheet) {
1 Like

That was it.

Thank you

you welcome
I’m glad I was able to help