1

My template contains an expression that produces an exception:

<h1>Foo: {{model.somebodyForgotToInitializeMe.foo}}</h1>

An error the model produces the following output on the console:

Uncaught EXCEPTION: TypeError: Cannot read property 'foo' of null in [
                {{model.somebodyForgotToInitializeMe.foo}}
             in SomeView@21:73]

That's not surprising. What is surprising is that this error brings down the entire Angular 2 application. Nothing else in the app responds after this has happened.

Is there a global exception handler I need to installed to prevent an error in a single binding expression killing my entire app?

This is a large medical application worked on by alot of developers. An exception in a UI component shouldn't take down the entire application.

Mark Rajcok
  • 362,217
  • 114
  • 495
  • 492
Mud
  • 28,277
  • 11
  • 59
  • 92
  • 2
    As of now bindings in Angular2 do not fail silently like Angular1. You need to use elvis operator is bindings `{{model.somebodyForgotToInitializeMe?.foo}}` – Chandermani Apr 13 '16 at 01:27
  • 2
    Its good to go with `global exception handle` but please note this doesn't happen in Angular2 as you mentioned, there must be some other problem I guess. Good to go with `Elvis Operator`. – micronyks Apr 13 '16 at 01:33
  • 2
    See [this similar question](http://stackoverflow.com/questions/35238428/how-to-tell-angular-to-not-block-the-whole-application-when-it-encounters-an-exc), might help with your concern. – Ankit Singh Apr 13 '16 at 08:56

1 Answers1

0

I have one hack <h1>Foo: {{(model.somebodyForgotToInitializeMe || {}).foo}}</h1> We use OR here when the variable is not available it used {} (blank object).

Omkar Yadav
  • 523
  • 1
  • 6
  • 14