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);
};
});