How to hide the bootstrap modal via typescript

Asked

Viewed 125 times

0

Looking at the bootstrap documentation I saw that it has a specific method to hide the modal via jquery:

.modal('hide')
$('#myModal').modal('hide')

The problem is that I use angular, so I need a way to call this function through typescript. Using jquery in my scenario is not feasible and I need to remove via typescript as it will only be closed after successful http request.

1 answer

0


I got it this way:

Set a local variable for the close button with the modal date-Dismiss:

<button [disabled]="loadingVinculacao" #fechaModalVinculacao type="button" class="btn btn-danger" data-dismiss="modal">Fechar</button>

No typescript Acessei it by viewchield:

  @ViewChild('fechaModalVinculacao') fechaModalVinculacao: ElementRef; //Acesso ao elemento do dom

I perform click the close button through typescript if my request is successfully made:

this.fechaModalVinculacao.nativeElement.click(); //Fecha o modal se a requisição for feita com sucesso

Browser other questions tagged

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