How to close all modals

hi guys, i want close all modals behind the top modal with dismiss.
how i can do

You have to keep the instance references to each modal so that you can programmatically reference them to call the close method.

What about a nice service? A method, who opens the modals and registers their instances in an array property of that service. All modals handled on a singleton like class. A second method to dismiss all instances in that array.

With best regards