如何在离子1中将日期从控制器传递给模态

时间:2018-04-19 09:48:32

标签: ios ionic-framework

我想将数据从控制器传递到离子模态,但我没有找到任何方法来做到这一点。所以请提出建议

what i have tried:-

var modalInstance = $modal.open({
  templateUrl: 'confirm_booking.html',
  controller: 'confirm_bookCtl',
  resolve: {
    items: function () {
      return $scope.items;
    }
  }
});

but $modal is undefined in controller

1 个答案:

答案 0 :(得分:0)

//首先,您不需要声明控制器,因为您可以从控制器中调用模态

.controller('MyController', function($scope, $ionicModal) {
   $ionicModal.fromTemplateUrl('templates/modal-template.html', {
      scope: $scope,
      animation: 'slide-in-up',
   }).then(function(modal) {
      $scope.modal = modal;
   });

   $scope.openModal = function() {
      $scope.modal.show();
   };

   $scope.closeModal = function() {
      $scope.modal.hide();
   };

   //Cleanup the modal when we're done with it!
   $scope.$on('$destroy', function() {
      $scope.modal.remove();
   });

   // Execute action on hide modal
   $scope.$on('modal.hidden', function() {
      // Execute action
   });

   // Execute action on remove modal
   $scope.$on('modal.removed', function() {
      // Execute action
   });
});

也许您可以访问此页面

https://www.tutorialspoint.com/ionic/ionic_js_modal.htm