title: How to pass data between controller on different files in Angularjs
body: <ul>
  <li><p>I have a page with the Controller_1</p></li>
  <li><p>the Controller_1 open a modal with a different controller on a different file that we call Controller_2</p></li>
  <li><p>and then the Controller_2 open another modal that have a different controller on a different file that we call Controller_3</p></li>
  </ul>
  
  <p>so we have:</p>
  
  <p>Controller_1  --Open Modal-->  Controller_2  --Open Modal-->  Controller_3</p>
  
  <p>when i close the modal with the Controller_3, I want to pass a value to the Controller_1.</p>
  
  <p>my code:</p>
  
  <p>Controller_1 open a modal with the Controller_2</p>
  
  <pre><code>app.controller("Controller_1", ['$scope', '$http', '$modal', 
  function ($scope, $http, $modal) {
  
  $scope.openModal_1 = function () {
  
      var modalInstance = $modal.open({
          templateUrl: '/SomeFolder/FileWithController_2',
          controller: 'Controller_2',
      });
  }
  
  }]);
  </code></pre>
  
  <p>Controller_2 open a modal with the Controller_3</p>
  
  <pre><code>app.controller("Controller_2", ['$scope', '$http', '$modalInstance', '$modal',
  function ($scope, $http, $modalInstance, $modal) {
  
  $scope.SaveSomething = function () {
  
              $http.post(url, obj)
                  .success(function (data) {
                          var modalInstance = $modal.open({
                          templateUrl: '/SomeFolder/FileWithController_3',
                          controller: 'Controller_3',
                          }
                      });
  
                  }).error(function () {
  
                  });
          };
      }]);
  </code></pre>
  
  <p>Controller_3 save something then close and pass some data to the Controller_1</p>
  
  <pre><code>app.controller("Controller_3", ['$scope', '$http', '$modalInstance',
  function ($scope, $http, $modalInstance) {        
  
     $scope.SaveSomething = function () {
  
                      $http.post(url, obj)
                          .success(function (data) {
  
                               ... pass some code to Controller_1 and close this modal.
  
                              });
  
                          }).error(function () {
  
                          });
                  };
              }]);
  </code></pre>
  
  <p>Assuming that everything is working fine and all I want to do is passing some data from Controller_3 to Controller_1.</p>
  
  <p>My question is:
  How I can pass the data from Controller_3 to Controller_1?</p>
  
  <p>I already tried pass the $scope when I open the modal as follows:</p>
  
  <pre><code>//from Controller_1 to Controller_2
  
       var modalInstance = $modal.open({
                  templateUrl: '/SomeFolder/FileWithController_2',
                  controller: 'Controller_2',
                  scope: $scope,
              });
  </code></pre>
  
  <p>in this case it work only for the Controller_2, so any modification on $scope will affect the Controller_1 but it is not working the same way if i do the same for Controller_3</p>
  
  <p>I tried $emit and $on but it do not work too because they are not parent and child like this: </p>
  
  <pre><code>&lt;div ng-controller="ParentCtrl"&gt;
      &lt;div ng-controller="ChildCtrl"&gt;&lt;/div&gt;
  &lt;/div&gt; 
  </code></pre>
  
  <p>they are complete different controllers in different files.</p>