本文介绍了从离子弹出中打开离子模态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何从 PopupController $ c中的
ModalController
中调用 openAddCardModal()
$ c>?
How do I call openAddCardModal()
in ModalController
from PopupController
?
function PopupController($scope, $ionicPopup, $timeout, $state) {
$scope.showPaymentOptionsPopup = function() {
$ionicPopup.confirm({
title: 'Payment Options',
cssClass: 'popup-vertical-buttons',
buttons:[
{
text: "Add",
type: 'button-positive',
onTap: function(){
// call openAddCardModal();
}
},
{
text: "Edit",
type: 'button-positive',
onTap: function(){
}
},
{
text: "Close",
type: 'button-dark',
onTap: function(){
}
}
]
});
};
}
function ModalController($scope, $ionicModal, $stateParams) {
// addCardModal()
$ionicModal.fromTemplateUrl('views/payment-add-card.view.html', {
scope: $scope,
animation: 'slide-in-up'
}).then(function(modal) {
$scope.addCardModal = modal;
})
$scope.openAddCardModal = function() {
$scope.addCardModal.show()
}
$scope.closeAddCardModal = function() {
$scope.addCardModal.hide();
};
$scope.$on('$destroy', function() {
$scope.addCardModal.remove();
}
推荐答案
使用AngularJS 服务设置控制器之间的通信
Use AngularJS Service to set communiaction between controllers
阅读本文:
您的服务可能如下所示:
Your service can look like this:
function ServiceName(){
var serviceFunction;
return {
set: function(funcFromCtrl){
serviceFunction = funcFromCtrl;
},
call: function(){
serviceFunction();
}
}
})
和控制器:
function PopupController($scope, $ionicPopup, $timeout, $state, ServiceName) {
...
onTap: function(){
ServiceName.call();
}
...
}
function ModalController($scope, $ionicModal, $stateParams, ServiceName) {
...
ServiceName.set($scope.openAddCardModal);
...
}
这篇关于从离子弹出中打开离子模态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!