title: How to return results from a $uibModal to parent controller
body: <h2>scope is undefined after callback from $uibModal</h2>
  <p>I have a directive (Angularjs) that has a controller, from there I am calling an uibModal where I want to modify some details of an object where I clicked.
  With the modal I am sending two parameters and a callback, everything seems to be ok but when angular go back to the callback function the scope of the controller (not the modal controller) is undefined, actually everything is undefined, how can I comunicate these two controllers, so when the user update something in the modal I can update it in the other controller.</p>
  <p><strong>modal.controller</strong></p>
  <pre><code>(function () {
      &quot;use strict&quot;;
  
      angular
          .module(&quot;app.users&quot;)
          .controller(&quot;editVitalCtrl&quot;, editVitalCtrl);
  
      editVitalCtrl.$inject = [&quot;items&quot;];
      function editVitalCtrl(items) {
  
          var vm = this;
          vm.modalTitle = &quot;Edit &quot; + items.vital.title;
          vm.vital = items.vital;
  
          vm.clickCancelModal = function () {
              vm.$close();
          }
  
          vm.clickSaveModal = function () {
              $scope.$result(items.saveCallback($scope.vital));
          }
  
      }
  })();
  </code></pre>
  <p><strong>directiveThatOpenTheModal.directive.js</strong></p>
  <pre><code>(function () {
      &quot;use strict&quot;;
  
      angular
          .module(&quot;app.users&quot;)
          .directive(&quot;directiveThatOpenTheModal&quot;, [
              function () {
                  return {
                      restrict: &quot;E&quot;,
                      scope: {
                          columnConfig: &quot;=columnConfig&quot;,
                          partnerId: &quot;=partnerId&quot;
                      },
                      link: {
                          pre: function (scope) {
  
                          }
                      },
                      controller: [&quot;$http&quot;, &quot;$scope&quot;, &quot;$uibModal&quot;,
                          function ($http, $scope, $uibModal) {
                              $scope.vitalList = [];
  
  
                              if ($scope.partnerId) {
  
                                  var params = {
                                      bankId: Number.isInteger($scope.partnerId) ? $scope.partnerId : -1
                                  };
  
                                  getColumnConfiguration(params, $http).success(function (data) {
                                      $scope.vitalList = data.columns;
                                  });
                              }
  
                              $scope.removeVital = function (vital) {
                                  removeVital(vital);
                              }
  
                              function callback(vital) {
                                  // Code here in callback, after code get in here everythings is undefined
                              }
  
                              $scope.editVital = function (vital) {
  
                                  $scope.modal = $uibModal.open({
                                      animation: true,
                                      windowClass: 'modal-add-cont modal-alerts',
                                      templateUrl: '/controller/view',
                                      controller: 'modalCtrl',
                                      resolve: {
                                          items: function () {
                                              return {
                                                  vital: vital,
                                                  saveCallback: callback,
                                                  partnerId: $scope.partnerId,
                                                  scope: $scope
                                              }
                                          }
                                      },
                                      size: 'lg'
                                  });
                              }
  
  
                              function removeVital(vital) {
                                  var index = $scope.vitalList.indexOf(vital);
                                  $scope.vitalList.splice(index, 1);
                              }
                          }],
                      templateUrl: '/route/Configuration'
                  };
              }]);
      function getColumnConfiguration(params, $http) {
          var url = &quot;/someroute/somemethod&quot;;
          return $http.get(url, { params: params });
      }
  })();
  </code></pre>