2016-04-15 13 views
0

Wie rufe ich openAddCardModal() in ModalController von PopupController an?Offenes ionisches Modal von ionischem Popup

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(); 
} 

Antwort

1

Verwenden AngularJS Dienst setzen Communiaction zwischen Controllern

Lesen Sie dazu: Communicate with controllers in angular js

Ihr Service wie folgt aussehen:

function ServiceName(){ 
    var serviceFunction; 

    return { 
     set: function(funcFromCtrl){ 
      serviceFunction = funcFromCtrl; 
     }, 
     call: function(){ 
      serviceFunction(); 
     } 
    } 
}) 

und Controller:

function PopupController($scope, $ionicPopup, $timeout, $state, ServiceName) { 
    ... 
     onTap: function(){ 
      ServiceName.call(); 
     } 
    ... 
} 

function ModalController($scope, $ionicModal, $stateParams, ServiceName) { 
    ... 
     ServiceName.set($scope.openAddCardModal); 
    ... 
} 
+0

Danke. Ich habe das versucht und bekomme immer den folgenden Fehler: http://imgur.com/PYVQMLG. Mein Code ist hier: http://pastebin.com/WAECu4r2. Zeile 113 ist 'call: function() { serviceFunction(); } ' – methuselah

+0

Sie haben Ihren Service Controller Abhängigkeiten nicht injiziert: ' Funktion PopupController ($ Umfang, $ ionicPopup, $ timeout, $ Zustand, ModalPopupCommunicationService) {......} ' –

+0

Sorry, ich vergaß hinzuzufügen die zum Pastebin. Ich habe das schon gemacht - 'function PopupController ($ scope, $ ionicPopup, $ timeout, $ state, ModalPopupCommunicationService)' und 'function ModalController ($ scope, $ ionicModal, $ stateParams, ModalPopupCommunicationService)'. Ihre Einbeziehung nimmt die Fehlermeldung nicht weg. – methuselah