Angularjs - How to close a modal $uibModal parent through a modal $uibModal daughter?

Asked

Viewed 123 times

0

I use Angularjs in the project. I have a modal that opens from a button of the parent modal. I want to insert a cancel button in the daughter modal, which will close the two modals.

  • How do you call the modal daughter within the parent modal ? can post the code ?

  • I have a modal that is called by a function in the controller. This modal calls another modal, declared in a directive. Can I close both modes at the same time? Can you understand explaining this? The code is gigantic, I have no way to post. The call of modals is through ng-click on Buttons.

  • What I’m guessing is that you can use Promisses in the action of opening the modal.

2 answers

0

I managed using $Emit in the function of closing the child modal and using the $on function in the directive that creates the parent modal, with the action of closing the parent modal.

0

The code below is to open the parent modal:

    $scope.openDetailsModal = function(){
        $scope.orderModalInstance = $uibModal.open({
            templateUrl: 'app/local/modals/details.html',
            scope: $scope,
            size: 'lg' 
    });

   $scope.orderModalInstance.result.then(function(){
            $scope.destroyOrderData();
        }).catch(function(e){
            $scope.destroyOrderData();
        });

    $scope.destroyOrderData = function(){
        $templateCache.remove($scope.orderModalInstance);
    }

On this page Details.html, there is a button that opens the child modal:

$scope.modalInstance = $uibModal.open({
    templateUrl: 'app/' + ($attrs.layout == 'account' ? '' : 'local/') + 'views/modals/page.html',
    size: 'md',
    scope: $scope
});

$scope.isModalOpen = true;
$scope.modalInstance.result.then(function(){
    $scope.destroyData();
}).catch(function(e){
    $scope.destroyData();
});

The function destroyData:


$scope.destroyData = function(){
        $scope.isModalOpen = false;
        $templateCache.remove($scope.modalInstance);
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.