How to handle template errors (and other errors) in angular 2?

空扰寡人 提交于 2019-12-03 14:19:55

You can use custom ErrorHandler:

class MyErrorHandler implements ErrorHandler {
  handleError(error) {
    // do something with the exception
  }
}
@NgModule({
  providers: [{provide: ErrorHandler, useClass: MyErrorHandler}]
})
class MyModule {}

Using ? mark is a solution around this while binding an object/array property to the template.

"user?.name?.firstname"

Looking for the more consolidated solution where we should able to handle template binding errors when huge data object comes from API and adding ? for each property in not a stable and lengthy solution.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!