[英]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.