Passing parameters to ActionSheet. How to do it?


#1

Hi there,

I’m trying to use ActionSheet to delete task on my app. ActionSheet slides in fine and all that, but I can’t figure out how to make the ‘Delete’ button actually work.

$scope.showActionsheet = function (task) {

    $ionicActionSheet.show({
        titleText: 'What you wanna do with this task?',
        buttons: [
            {
                text: 'Edit <i class="icon ion-ios7-compose-outline" i>'
            },
  ],
        destructiveText: 'Delete',
        cancelText: 'Cancel',
        cancel: function () {
            console.log('CANCELLED');
        },
        buttonClicked: function (index) {
            console.log('BUTTON CLICKED', index);
            if (index = 0) {
                alert("Edit button");
            }
            return true;
        },
        destructiveButtonClicked: function (task) {
            
            // Is it here where I should do it?
            
            return true;
        }
    });
};

I’m not sure how should I provide the ‘task’ parameter to the action sheet in order to delete it.
I’ve got this function for deleting:

$scope.deletingTask = function (task) {
    database.deleteTask(task.id).then(function () {
        $scope.refreshList();
    }, function (err) {
        $window.alert(err);
    });
    $scope.tasks.splice($scope.tasks.indexOf(task), 1);
};

Thanks for your help :slight_smile:


#2

Alright, I fixed it myself.

I just didn’t need to give this function a ‘task’ object and it was crashing there.
so it should be:

destructiveButtonClicked: function () {
// delete task here
}

anyway, you need to provide the object when calling the showActionSheet() function.


#3

Hi, i got the same problem. can i knw what you put in ur html file? izzit juz
ng-click=“showActionsheet()”


#4

Sorry for that,m I’ve been working on other platforms and didn’t really pay attention to this forum…
here my html

the Action Sheet:

<script id="popover.html" type="text/ng-template">
      <ion-popover-view>
        <ion-content>
          <div class="list">
            <a class="item" href="#">
              {{ "HISTORY" | translate }}
            </a>
            <a class="item" href="#">
              {{ "SEARCH" | translate }}
            </a>
            <a class="item" href="#">
              {{ "LOGOUT" | translate }}
            </a>
            
          </div>
        </ion-content>
      </ion-popover-view>
    </script>

and the trigger was

on-hold="showActionsheet(task)"

I guess it’s kinda late, but I post it here in case someone gets to the thread with the same issue.