title: Angular.js callback from another controller
body: <p>In my angular project I'm using <a href="https://material.angularjs.org/latest/" rel="nofollow noreferrer">Angular.js material</a>. And I want to show <code>$mdialog</code> with custom controller, where user changes some data and this data should be applied to my <code>$scope</code> variable. Example what I do now:</p>
  
  <pre><code>function myControllerFn($scope, MyService){
     // I do copy of my service variable because I don't want to change it until user will click save button
     $scope.name = angular.copy(MyService.name); 
  
     $scope.editCurrentProfile = function() {
         $scope.showEditProfileDialog($scope.name).then(function(name){
                      $scope.name = name;
         }
     }
  
     $scope.showEditProfileDialog = function(name) {
        var deferred = $q.defer();
        $mdDialog.show({
           controller: 'editProfileViewCtrl',
           templateUrl: 'controllers/editProfileDialog.tmpl.html',
           locals: {
               name: name,
               deferred: deferred
           }
        });
           return deferred.promise;
       };
  }
  </code></pre>
  
  <p>Then in dialog controller I do:</p>
  
  <pre><code>function editProfileViewCtrl($scope, name, deffered) {
      deferred.resolve('newName');
  }
  </code></pre>
  
  <p>But I think it is the wrong way. So what is the best way to communicate between two view controllers in angular without new service ? Or better create another service like: <code>EditDialogService</code>, where I will save results ?</p>