gpt4 book ai didi

javascript - 在 ionicPopup 关闭时触发 ionicModal

转载 作者:行者123 更新时间:2023-12-03 06:54:23 25 4
gpt4 key购买 nike

我想在用户按下按钮时打开 ionic 模式,但在用户按下按钮时关闭 ionic 弹出窗口。我怎样才能做到这一点?

目前,在每种情况下都会打开 ionic 弹出窗口。这是到目前为止我的代码:

services.js

 function PopupService($ionicPopup) {

function acceptAppointmentPopup(scope) {
return $ionicPopup.show({
title: 'Are you sure you want to accept this appointment?',
scope: scope,
buttons: [{
text: '<b>Yes</b>',
type: 'button-positive',
onTap: function(e) {}
}, {
text: 'No',
onTap: function(e) {}
}, ]
})
}

return {
acceptAppointmentPopup: acceptAppointmentPopup
};
}

controller.js

function BusinessPendingAcceptanceCtrl($scope, PopupService, ModalService) {

$scope.newMessageModal = function() {
ModalService.show('templates/modals/new-message.html', 'ConsumerNotificationsCtrl as vm');
}

$scope.showAcceptAppointmentPopup = function() {
$scope.data = {}
var myPopup = PopupService.acceptAppointmentPopup($scope);
myPopup.then(function(res) {
$scope.newMessageModal();
});
};
}

最佳答案

$ionicPopup 支持 confirm (YES、NO 对话框),它返回一个 promise 并作为参数通过结果。您可以像这样使用它:

$ionicPopup.confirm({ // example taken from official documentation
title: 'Consume Ice Cream',
template: 'Are you sure you want to eat this ice cream?'
}).then(function (result) {
if (result) {
// At this point user confirmed that they want to eat the ice cream,
// so lets open a modal to visually show the user how the ice cream is being consumed
$ionicModal.fromTemplateUrl('my-modal.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.modal = modal;
$scope.modal.show();
// This is where the user starts drooling :P
});
} else {
// This user apparently hates ice cream, which is ridiculous...
}
});

您可以通过 official documentation page 获取更多信息.

<小时/>

将我的示例集成到您的代码中:

services.js

function PopupService($ionicPopup) {
function acceptAppointmentPopup(scope) {
return $ionicPopup.show({
title: 'Are you sure you want to accept this appointment?',
scope: scope,
buttons: [{
text: '<b>Yes</b>',
type: 'button-positive',
onTap: function(e) {
return true;
}
}, {
text: 'No',
onTap: function(e) {
return false;
}
}]
})
}

return {
acceptAppointmentPopup: acceptAppointmentPopup
};
}

controller.js

function BusinessPendingAcceptanceCtrl($scope, PopupService, ModalService) {

$scope.newMessageModal = function() {
ModalService.show('templates/modals/new-message.html', 'ConsumerNotificationsCtrl as vm');
}

$scope.showAcceptAppointmentPopup = function() {
$scope.data = {}
var myPopup = PopupService.acceptAppointmentPopup($scope);
myPopup.then(function(res) {
if (res) { // Here we check if user pressed Yes - Yes button returns true
$scope.newMessageModal();
}
});
};
}

关于javascript - 在 ionicPopup 关闭时触发 ionicModal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37346846/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com