Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions packages/core/src/error_handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,19 @@ const globalErrorListeners = new InjectionToken<void>(ngDevMode ? 'GlobalErrorLi
e.preventDefault();
};

window.addEventListener('unhandledrejection', rejectionListener);
window.addEventListener('error', errorListener);
const setupEventListeners = () => {
window.addEventListener('unhandledrejection', rejectionListener);
window.addEventListener('error', errorListener);
};

// Angular doesn't have to run change detection whenever any asynchronous tasks are invoked in
// the scope of this functionality.
if (typeof Zone !== 'undefined') {
Zone.root.run(setupEventListeners);
} else {
setupEventListeners();
}

inject(DestroyRef).onDestroy(() => {
window.removeEventListener('error', errorListener);
window.removeEventListener('unhandledrejection', rejectionListener);
Expand Down