Could someone guide me in the right direction on how to implement a modal system in angular2 having a lot of modal windows? Right now a modal containing a component to search customers looks something like this:
<modal #searchModal title="Search">
<search-customer (complete)="searchModal.hide()">
</search-customer>
</modal>
Basically modal is a simple component fixed on the middle of the screen, I close the modal when the component inside the modal emits an event. On each show()
and close()
the modal gets a Z-index
from a service and applies/removes some styles.
So far the problems are:
- On pressing
Esc
I have to close the last opened modal, how can I access that component from the service ? Can I somehow pass a reference to the service onmodal.show()
? - If an exception occurs in the service, how can I access a modal to show my problem? Have a modal component in the root component of my app(If so, then again I have the first problem, how can I access it from inside the service)?
- I can easily open and close a modal from template like in the previous example
(complete)="searchModal.hide()"
but how can I do this from inside the class methods?
Can someone tell me the right way to do this, or how to solve the existing problems ?