簡體   English   中英

如何在buttonClicked的$ ionicActionSheet之外調用函數?

[英]How to call a function outside $ionicActionSheet on buttonClicked?

我正在嘗試使用$ionicActionSheet執行函數。 此外,在下面的示例中,當用戶單擊第一個選項以“執行其他操作”時,我想調用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 ,而是按鈕對象。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM