dwmkerr / angular-modal-service

Modal service for AngularJS - supports creating popups and modals via a service.
MIT License
626 stars 321 forks source link

Modal not getting closed #234

Closed NicoJuicy closed 6 years ago

NicoJuicy commented 6 years ago

I have seen the other comments, ending in #225

But i don't have a $on on $rootScope, so that shouldn't be the problem.

My modal is getting called multiple times on close/hiding. Eg. [http://beta.belgianbrewed.com/en/product/budweiser-24x30cl](Example page)

The file in question can be found on /assets/angular/controllers/ShopActionController.js

I cross posted my question on StackOverflow ( my previous question with the same problem was dated 1 month ago)

smohammedyasin commented 6 years ago

@NicoJuicy, I have same issue, i don't use $on or $rootScope. did you solved the issue?

decherneyge commented 6 years ago

You need to add your bootstrap modal hidden listener to the dialog controller context.

app.controller('ShopActionDialogController', ['$scope', '$element', 'CurrentProduct', 'close', function ($scope, $element, CurrentProduct, close) {

$scope.CurrentProduct = CurrentProduct;
console.log("Dialog called and ...");
console.log(CurrentProduct);

//modal.element.modal();

//modal.close.then(function (result) {
//    $scope.message = result ? "You said Yes" : "You said No";
//});

//listen for when the modal is dismissed and resolve the ModalService Close promise
        $element.on('hidden.bs.modal', function (e) {

            close({
                currentProduct: CurrentProduct
            }, 200); // close, but give 200ms for bootstrap to animate
        });

}]);
dwmkerr commented 6 years ago

Thanks to @decherneyge this is now in the bootstrap sample, so closing this issue now. Please re-open if needed!