Exit Confirmation Sweetalert 2 - Angular

Asked

Viewed 103 times

1

Boa Tarde Personal,

I recently met the Sweet Alert library. I’m trying to use it to leave a page, currently count only with a Function in Typescript.

I would like to know how to transfer Sweet Alert 2 to that output confirmation.

  confirmarSair() {
const r = window.confirm("deseja sair?");
if (r) {
  window.sessionStorage.clear();
  window.location.href = `${environment.logoutUrl}?redirect_uri=${environment.noderedUrl}`;
}

inserir a descrição da imagem aqui }

1 answer

2

Navigating through documentation it is possible to find several examples.

What you intend to accomplish can be done as follows:

Swal.fire({
    title: 'Deseja sair?',
    type: 'question',
    confirmButtonText: 'Sair',
    showCancelButton: true,
    cancelButtonText: 'Cancelar'
})
.then((result) => {
    if (result.value) {
        window.sessionStorage.clear();
        window.location.href = `${environment.logoutUrl}?redirect_uri=${environment.noderedUrl}`;  
    }
})

Browser other questions tagged

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