使用angular2 @HostListener时onbeforeunload确认对话框未显示 [英] onbeforeunload confirm dialog not showing when angular2 @HostListener is used

查看:215
本文介绍了使用angular2 @HostListener时onbeforeunload确认对话框未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用@HostListener挂钩,但未显示确认对话框(询问:是否要离开此页面?...或是否要重新加载此页面?).

Using @HostListener hook, but confirm dialog (that asks: Do you want to Leave this page? ...or Do you want to Reload this page?) is not showing.

该代码有效,但是未显示确认对话框.

The code works, but the confirm dialog is not showing.

这是我拥有的:

@HostListener('window:beforeunload', ['$event'])
public doSomething($event) {
    console.log("do I see this?") // <---- this logs to the console.

    return "something else";
}

但是我看不到:

推荐答案

返回false而不是字符串"something else"可以解决此问题,并显示确认对话框.

returning false instead of the string "something else" fixes the problem and the confirm dialog is shown.

角度绑定很可能会修改返回值

It's quite possible that angular bindings modify the return value

这篇关于使用angular2 @HostListener时onbeforeunload确认对话框未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆