Does the angular renderer2 have any method to click on an element?

Asked

Viewed 62 times

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">&times;</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 tag button. Then your model would be. <button ... (click)='funcaoFechar()'>

  • 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...

  • using jquery would look like this $('#idModal').modal('hide'). And don’t forget to declare the $ after Imports declare var $

  • I want to do in angular!

  • 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.

  • I want to know if it is possible with the angular Renderer. I know that bootstrap uses jquery.

Show 1 more comment
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.