I have a angular project with modals, and I want send multiple (two) parameters when I close, the problem is the second argument it gives undefined, my code is the following
/*Modal controller*/
angular.module('assetModule')
  .controller('assetModalLocationCtrl', ['locationRESTService','$modalInstance','$scope', '$q', assetModalLocationCtrl]);
    function assetModalLocationCtrl (locationRESTService, $modalInstance, $scope, $q) {  
    this.ok = function () {   
      $scope.info.selected = selected ($scope.data.locations)
      $modalInstance.close($scope.data.locations, $scope.info.selected);      
    };
}
/*Controller that invoke the modal*/
this.modalLocation = function modalLocation (size){
    var modalInstance = $modal.open({
      animation: this.animationsEnabled,
      templateUrl: 'views/asset/assetLocationModal.html',
      controller: 'assetModalLocationCtrl',
      controllerAs: 'modalLocation',
      size: size,
    });
    modalInstance.result.then(function (selectedItem, locationList) {
     console.log(selectedItem);
     console.log(locationList);
    }, function () {
      console.log('Modal dismissed at: ' + new Date());
    });
}
                You cannot do that as a promise resolves to only one value, you can combine them to an object.
 $modalInstance.close({locations: $scope.data.locations, selected: $scope.info.selected});  
and read them accordingly when the promise is resolved.
modalInstance.result.then(function (transferData) {
   console.log(transferData.selected);
   console.log(transferData.locations);
}, function () {
    console.log('Modal dismissed at: ' + new Date());
});
Side Note:
With Typescript or Babel or any other ES6 polyfill you could make use of object destructuring syntax and write is as:
modalInstance.result.then({locations, selected}) => {
   console.log(locations);
   console.log(selected);
}
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With