angular 6 HostListener无法读取null的属性'getGlobalEventTarget'(getDOM())

时间:2018-06-22 23:30:49

标签: events angular6

我想在角度6的卸载事件之前绑定事件。为此,我正在使用HostListener。我遇到了错误

AppComponent_Host.ngfactory.js? [sm]:1 ERROR TypeError: Cannot read property 'getGlobalEventTarget' of null
    at DomEventsPlugin.EventManagerPlugin.addGlobalEventListener (platform-browser.js:2420)
    at EventManager.addGlobalEventListener (platform-browser.js:2355)
    at DefaultDomRenderer2.listen (platform-browser.js:2991)
    at DebugRenderer2.listen (core.js:15475)
    at listenToElementOutputs (core.js:10618)
    at createViewNodes (core.js:13751)
    at createRootView (core.js:13673)
    at callWithDebugContext (core.js:15098)
    at Object.debugCreateRootView [as createRootView] (core.js:14381)
    at ComponentFactory_.create (core.js:11278)

这是我的代码。

app.component.ts

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html'
})
export class AppComponent {
 constructor(){
}
@HostListener('window:beforeunload')
public onrefresh() {
} 

app.component.html

<router-outlet >
</router-outlet>

我已经调试,发现getDOM()返回null,但是努力解决该问题。

0 个答案:

没有答案