Angular 1.6: Open a uibmodal inside another module using "solve"?

1

I have a problem to open a uibmodal inside another uibmodal passing the same through resolves. I have two modals declared inside the same controller, Modal1 and Modal2. Modal 1 passes modal2 in resolves, everything works fine, minus the "result.then" question, modal 2 returns an x value for a $ scopo, however it returns the value for the main controller and I would like it to be returned for Modal1

See the example: link

Does anyone know how to solve this question? I've tried using angular.copy but it does not work: (

Thank you

    
asked by anonymous 21.03.2018 / 12:14

1 answer

0

One option is to have the modals open function receive a callback:

angular.module('ui.bootstrap.demo', ['ngAnimate', 'ui.bootstrap']);
angular.module('ui.bootstrap.demo').controller('ModalDemoCtrl', function ($scope, $uibModal) {

  //abre um Modal
  function openModal( templateUrl, controller, resolve, callback ){
    return $uibModal.open({
      templateUrl,
      controller,
      resolve
    }).result.then( callback || angular.noop );
  }

  //abre modal 1
  const openModal1 = (resolve, callback) => 
    openModal( 'modaltemplate1.html', 'ModalController1', resolve, callback);

  //abre modal 2
  const openModal2 = (resolve, callback) =>
    openModal( 'modaltemplate2.html', 'ModalController2', resolve, callback);


  $scope.produtos = 0;

  $scope.openModal1 = function () {
    openModal1({
      openModal2: function() {
        //envia a função de abrir o modal 2
        return openModal2;
      }
    });
  };

  $scope.openModal2 = () => openModal2({},  result => $scope.produtos = result);

});

angular.module('ui.bootstrap.demo').controller('ModalController1', function ($scope, $uibModalInstance, $uibModal, openModal2) {

  $scope.produtos = 1;

  $scope.ok = () => $uibModalInstance.close($scope.produtos);

  $scope.openModal2 = () => openModal2({}, result => $scope.produtos = result );

});

angular.module('ui.bootstrap.demo').controller('ModalController2', function ($scope, $uibModalInstance, $uibModal) {

  $scope.produtos = 2;

  $scope.ok = function () {
    $uibModalInstance.close($scope.produtos);
  };

});
    
21.03.2018 / 12:54