如何从openAddCardModal()
致电ModalController
中的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();
}
答案 0 :(得分:1)
使用AngularJS 服务设置控制器之间的通信
阅读本文:Communicate with controllers in angular js
您的服务可能如下所示:
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);
...
}