如何处理角度2中的模板错误(和其他错误)? [英] How to handle template errors (and other errors) in angular 2?

查看:79
本文介绍了如何处理角度2中的模板错误(和其他错误)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

角度2出现模板错误时,整个应用程序将无法正常工作.

When ever there is a template error in angular 2, the entire application fails to work.

不仅具有导致错误,无法正常工作的模板的组件,而且应用程序的其余部分都可以正常工作吗?

Shouldn't only the component that had the template that caused the error, fail to work and the rest of the application be working fine?

如何处理错误,以使应用程序在发生错误时不会停止响应?

How to handle errors so that the application won't stop being responsive when an error occurs?

推荐答案

您可以使用自定义

You can use custom ErrorHandler:

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

这篇关于如何处理角度2中的模板错误(和其他错误)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆