Javascript 如何在点击ionicActionSheet选项时打开ionicPopup?
当用户点击操作表上的“自定义”按钮时,我试图打开一个弹出窗口,但我不知道如何在两者之间进行交互。下面是我的最佳猜测,当我在视图中调用ng click=“showPrompt()”时,弹出窗口会被触发,但当我尝试从操作表上的buttonClicked事件中执行此操作时,它是不可能的Javascript 如何在点击ionicActionSheet选项时打开ionicPopup?,javascript,angularjs,ionic-framework,Javascript,Angularjs,Ionic Framework,当用户点击操作表上的“自定义”按钮时,我试图打开一个弹出窗口,但我不知道如何在两者之间进行交互。下面是我的最佳猜测,当我在视图中调用ng click=“showPrompt()”时,弹出窗口会被触发,但当我尝试从操作表上的buttonClicked事件中执行此操作时,它是不可能的 .controller('TablesCtrl', function($scope, $ionicPopup, $ionicActionSheet) { $scope.tables = []; /*
.controller('TablesCtrl', function($scope, $ionicPopup, $ionicActionSheet) {
$scope.tables = [];
/* Choose Number of Guests */
$scope.showActionsheet = function($ionicPopup) {
$ionicActionSheet.show({
titleText: 'How many guests?',
buttons: [
{ text: '1' },
{ text: '2' },
{ text: '3' },
{ text: '4' },
{ text: '5' },
{ text: '6' },
{ text: 'Custom' }
],
cancelText: 'Cancel',
cancel: function() {
console.log('CANCELLED');
},
buttonClicked: function(index, $ionicPopup) {
console.log('BUTTON CLICKED', index);
if(index==6){showPrompt();}
return true;
}
});
};
/* CUSTOM Number of Guests */
$scope.showPrompt = function() {
var myPopup = $ionicPopup.show({
template: '<input type="password" ng-model="data.wifi">',
title: 'Enter Wi-Fi Password',
subTitle: 'Please use normal things',
scope: $scope,
buttons: [
{ text: 'Cancel' },
{
text: '<b>Save</b>',
type: 'button-positive',
onTap: function(e) {
if (!$scope.data.wifi) {
//don't allow the user to close unless he enters wifi password
e.preventDefault();
} else {
return $scope.data.wifi;
}
}
},
]
});
};
})
.controller('tableCtrl',函数($scope、$ionicPopup、$ionicActionSheet){
$scope.tables=[];
/*选择客人的数量*/
$scope.showActionsheet=函数($ionicPopup){
$IoniActionSheet.show({
titleText:“有多少客人?”,
按钮:[
{text:'1'},
{文本:'2'},
{文本:'3'},
{文本:'4'},
{文本:'5'},
{文本:'6'},
{text:'自定义'}
],
cancelText:“取消”,
取消:函数(){
console.log('CANCELLED');
},
buttonClicked:函数(索引$ionicPopup){
日志('点击按钮',索引);
如果(索引==6){showPrompt();}
返回true;
}
});
};
/*客流量*/
$scope.showPrompt=函数(){
var myPopup=$ionicPopup.show({
模板:“”,
标题:“输入Wi-Fi密码”,
副标题:"请用正常的东西",,
范围:$scope,
按钮:[
{text:'取消'},
{
文本:“保存”,
键入:'按钮正',
onTap:功能(e){
if(!$scope.data.wifi){
//除非用户输入wifi密码,否则不允许用户关闭
e、 预防默认值();
}否则{
返回$scope.data.wifi;
}
}
},
]
});
};
})
尝试使用$scope
,因为该函数在该上下文中未定义,但$scope是通过闭包定义的:
if(index==6){$scope.showPrompt();}
哈哈,我就知道这很简单。很抱歉,对于Angular,甚至MVC来说,仍然是新手。非常感谢!