How to pass data from $ionicModal to main controller?


I have following example in [CodePan][1] where I try to change the email over modal.

As I know $ionicModal has the same scope. However I can pass data to modal but when I press “Apply” - nothing happens.

I tried so far to add watcher but with no success:

  $ = 'old'; 
    $scope.$watch('email', function(newV, oldV){
        if(newV !== oldV){
            $ = newV;


$scope.applyModal = function(newValue) {             
          console.log('1: ' +  $;
          $ = newValue;
           console.log('2: ' +  $;  
          $scope.modalCtrl.hide();  // we see new value

On press “Apply”

Do I miss something?


Modals actually have an isolated scope. I have had similar issues with modals, and there seem to be two ways to deal with it.

  1. Pass the value back to the parent model, applyModel(email) would pass the email value in the model scope to the method to be used to pass along.
  2. Use a second level object that can be better shared $
1 Like

This is a point. The modal in native Angular has isolate scope and we use promise to get response back. In our case I really don’t see any solution to pass value to parent scope. The parent scope has different id from where I called the modal.

Can you change my demo I posted?

It will work (at least for me) only if modal will stay with the same scope (actually this is what I did but it seems messy).


I just modified your example using the two methods above.


The first lets you maintain the isolated scope. In both examples the model in the main controller is changed to $scope.modalData.msg.

While the scopes are different between the modal and controller, the modal is a child and so the parent values are available (See Scope Hierarchies). What I haven’t dug into is why putting a string model directly on the scope fails ($scope.msg) but having it as an object seems to work ($scope.modalData.msg).


Thank you, very appreciate your effort

In my case… I could update the data from cannot be bind on the main view… is there something wrong with my code ?
Main Controller

$ionicModal.fromTemplateUrl('post-modal.html', {
        scope: $scope,
        animation: 'slide-in-up'
    }).then(function (modal) {
        $scope.modal = modal;

Modal Controller
$ = function () {'Save'); $scope.announcements.push( { id: $scope.announcements.length+1, name: 'April Marie Bandivas', content: 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Ipsa nobis ullam, aliquam illum reiciendis velit architecto a quisquam, perspiciatis eum excepturi delectus optio. Labore, inventore fuga, itaque molestiae ex dignissimos.', files: [ { id: 1, file: 'sansa-snowcastle.png', type: 'image', } ], avatar: 'tyrion.jpg', comments: 120, time: 'Just now' } ); $scope.modal.hide();$scope.announcements); };

the code was successfuly executed and updated the $scope.announcement from the main controller… however it wont display the new data on the view…