How to pass data from parent controller to ionicModal?


I have following Demo where we start basic modal.

From angular ui we have ability to pass data to modal by using resolve key:

var modalInstance = ${
      templateUrl: 'myModalContent.html',
      controller: ModalInstanceCtrl,
      resolve: {
        test: function () {
          return 'test variable';

How could we do the same with $ionicModal?

I opened ionic.bundle.js, seems we can’t. :frowning:

For sure I can store data in service and load it from modal.

Any suggestions?


1 Like

You can’t do that here because Modals are not routes or states in Ionic. However, you can give the modal access the original controller’s scope by passing in the scope parameter:

        $ionicModal.fromTemplateUrl('modal.html', function(modal) {
          $scope.modalCtrl = modal;
        }, {
          scope: $scope,  /// GIVE THE MODAL ACCESS TO PARENT SCOPE
          animation: 'slide-in-left',//'slide-left-right', 'slide-in-up', 'slide-right-left'
          focusFirstInput: true

See sample :


Thank you, works fine.

FYI…$scope.modal should be replaced with $scope.modalCtrl in your codepen.

Right, this is working example. Thanks.

Hello, I am having the same question as this one. However I have some confusion about which is the “original controller’s scope”

In the child, should I access the parent controller using $scope.modal ??
(I tried, seems not working)

here are part of my codes

 $scope.productGroupsBtnTap = function () {
  	console.log('Product Groups Btn tap');
  	$ionicModal.fromTemplateUrl('templates/productGroup.html', function(modal) {
      modal.productGroups = product.productGroups; = 'ProductGroups';
      $scope.modal = modal;

    }, {
      scope: $scope,
      animation: 'slide-in-up'

at the ProductGroup Controller

.controller('ProductGroupCtrl', function($scope, SharedProperties, $ionicModal) {
  console.log('Product Group controller');
  $scope.navTitle = SharedProperties.getProperty('navTitle');
  // $scope.navTitle = 'Return Policy';
  var option = $scope.modal.productGroups;
  // $scope.option = option;

  $scope.optionSelected = function($index) {
  	var selectedValue = option[$index];



Anyone has ideas which part goes wrong?

It throw an error of “productGroups of undefined”

Many Thanks

Just found that they are sharing the same "$scope"
very confusion but it does work.

This not work…sadly.
BTW, I found this link, this works fine:

I dont totally get it? whats the trick ? how they share ? is it because the controllers are not in the routes ? but on the view… does it do the trick ?