estus estus - 1 year ago 110
Javascript Question

Notify on Angular 2 app initialization error

An uncaught exception (injector or just random error) in any component during bootstrap may lead to bootstrap failure.

Due to browser incompatibility the app may not start bootstrap process at all.

I'm looking for a way to notify a user (with alert, modal, etc) on critical error that happened during Angular 2 app initialization, so a user could be sure that the app not just loads forever but failed for some reason.

What's the good recipe to handle this case in Angular 2?

Answer Source

PlatformRef.bootstrapModule return's a promise where we can .catch the error, while bootstrap(initializing) the app.

    .catch(er‌​r => console.error(err));

There was a bug, which was just resolved(changelog). Thanks to @estus, for pointing it out.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download