如何在 buttonClicked 上调用 $ionicActionSheet 之外的函数?

How to call a function outside $ionicActionSheet on buttonClicked?

我正在尝试使用 $ionicActionSheet 来执行一个函数。此外,在下面的示例中,我想在用户单击 "do something else" 的第一个选项时调用 doSomethingElse()。我可以在函数buttonClicked()内成功执行命令,但它不想调用外部函数

// 在控制器内

$scope.doSomethingElse = function(textStr) {
    window.alert(textStr)
}

$scope.showActions = function(friendName) {
    $ionicActionSheet.show({
     buttons: [
       { text: 'do something else },
       { text: 'do something' },
     ],
     destructiveText: 'View all',
     titleText: '<h4>' + friendName + ' </h4>',
     cancelText: 'Cancel',
     buttonClicked: function(index, $scope) {
       if(index==0) {
         // window.alert("Hello");  works fine
         $scope.doSomethingElse("Index 0")
       }
       if(index==1) {
         // window.alert("Hello");  works fine too
         $scope.doSomethingElse("Index 1")
       }
       return true;
     },
     destructiveButtonClicked: function() {
       window.alert("Hey All");
       return true;
     }
   });

}

替换以下内容:

buttonClicked: function(index, $scope) {

与:

buttonClicked: function(index) {

或者将第二个参数重命名为例如:

buttonClicked: function(index, button) {

否则会覆盖$scope变量。传递给 buttonClicked 函数的第二个参数不是 $scope,而是按钮对象。