“Uncaught EXCEPTION” in view binding brings down entire Angular 2 app

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.

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

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