0
I have a modal bootstrap that at some point of my TS code I must close it.
Currently to close this modal I use a local variable in the close button of the modal and use viewChild to click on it:
<button #fechaModalAlteracaoAnuncio type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
@ViewChild('fechaModalAlteracaoAnuncio') fechaModalAlteracaoAnuncio: ElementRef;
And then in my job:
salvaAlteracoesAnuncio() {
this.fechaModalAlteracaoAnuncio.nativeElement.click();
}
I saw on some websites saying that access the DOM with viewChild
it’s not safe, we should use the Renderer2
. However, I couldn’t find any way to click with Nderer.
Do you know any alternative way to close the modal through the TS?
Try to use
(click)
within your tagbutton
. Then your model would be.<button ... (click)='funcaoFechar()'>
– Victor Henrique
At a certain point in my saving functionAlteracoesAn I must close the modal, so the close of the modal has to be done through the non-thtml TS...
– veroneseComS
using jquery would look like this
$('#idModal').modal('hide')
. And don’t forget to declare the$
after Importsdeclare var $
– Victor Henrique
I want to do in angular!
– veroneseComS
What logic do you want to make to close the modal ? Bootstrap is an API that uses
jquery
in its components. At the end, when you click the close button the call that will be executed is this.– Victor Henrique
I want to know if it is possible with the angular Renderer. I know that bootstrap uses jquery.
– veroneseComS