Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

136
Visualizações
Angular Warning Message Before Exiting a Page

In my app, I want a feature that gives a warning message when I try to; close the tab, exit the page or reload the page. The code I wrote for it is below. Right now, it gives a warning. Yet, it still exits the page before I can click “yes” or “no”. How can I fix this?

HTML:

<div (window:beforeunload)="onWindowClose($event)"></div>

TS:

    @HostListener('window:beforeunload', ['$event'])
onWindowClose(event: any): void {

 this.confirmDialogRef = this._dialog.open(FuseConfirmDialogComponent, {
    disableClose: false,
});
this.confirmDialogRef.componentInstance.confirmMessage =
    "You will be exiting the page, are you sure?";

this.confirmDialogRef.afterClosed().subscribe((result) => {});

  event.preventDefault();
  event.returnValue = false;



}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Why not use a Directive to achieve this

@Directive({selector: 'button[counting]'})
class CountClicks {
  numberOfClicks = 0;

  @HostListener('click', ['$event.target'])
  onClick(btn) {
    console.log('button', btn, 'number of clicks:', this.numberOfClicks++);
 }
}

@Component({
  selector: 'app',
  template: '<button counting>Increment</button>',
})
class App {}

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda