Reputation: 1106
I have a timer in my app. If the time is up it's transfer user to login page.
How to detect if the MdDialog is open and close it?
I don't want to use angular.element(document).find('md-dialod').remove()
- because some elements like md-backdrop
or smth else stil exists.
Is there any solutions for this situations?
Upvotes: 0
Views: 1603
Reputation: 625
(for anyone still using Angular.js in 2022 😌)
const count = $document.find("md-dialog").length;
for (let i = 0; i < count; ++i) $mdDialog.cancel();
Park this code anywhere you'd like to trigger your event. I thought you'd need a reference to the existing obj returned by called $mdDialog.show() but apparently not.
Upvotes: 1
Reputation: 3513
Are you using multiple dialog opening customization? This should work:
$timeout(function(){
$mdDialog.cancel();
}, 8000);
Here $mdDialog.cancel()
hides an existing dialog and reject the promise returned from $mdDialog.show()
. And even if it's not open calling it will not cause any error.
https://plnkr.co/edit/9nTJNvpO6qU1Bnq1mVML?p=preview
Upvotes: 2