Usually we use data-target="#myModal"
in the to open a modal. Right now I need use codes to control when to open the modal.
If I use [hidden]
or *ngIf
to show it, I need remove class="modal fade"
, otherwise, the modal will never show. Like this:
However, in this case, after removing class="modal fade"
, the modal won't fade in and has no shade in the background. And what's worse, it will show at the screen bottom instead of screen center.
Is there a way to keep class="modal fade"
and use code to open it?
Answer
This is one way I found. You can add a hidden button:
Then use the code to "click" the button to open the modal:
document.getElementById("openModalButton").click();
This way can keep the bootstrap style of the modal and the fade in animation.
No comments:
Post a Comment