angular - 我如何跟踪 ionic 2 中 app.component.ts 中的每个错误

标签 angular typescript ionic2 ionic3 ionic-native

<分区>

我正在使用 ionic 2。我想跟踪 ionic 2 app.component.ts 文件中发生的每个错误。是否有任何解决方案?

提前致谢

最佳答案

您需要使用 IonicErrorHandler类。这是一个全局错误处理程序。

The IonicErrorHandler intercepts the default Console error handling and displays runtime errors as an overlay when using Ionic's Dev Build Server.

app.module.ts

import { NgModule, ErrorHandler } from '@angular/core';
import { IonicErrorHandler } from 'ionic-angular';

@NgModule({
  providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }]
})
class AppModule {}

现在,如果您在应用程序的任何地方执行 throw new Error('Im error'),您将看到控制台消息。

这里有一篇很棒的文章 custom error handling .

关于angular - 我如何跟踪 ionic 2 中 app.component.ts 中的每个错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46029664/

相关文章:

angular - Angular Elements 和 Stencil 的技术概念

java - Spring 响应中 JSON 中位置 0 处出现意外标记 S

javascript - ES6 Promise/Typescript 和 Bluebird Promise

javascript - ng2-translate 与 Charts.js 结合使用组件文件

firebase - 如何使用 Firebase 实现 LinkedIn 身份验证?

javascript - 将元素的属性传递给 Angular 4/5 中的函数

angular - 如何在 ng2-smart-table 中添加自定义 css

angular - 如何在 Angular 8 中使用 TS 下载 pdf 格式的页面

node.js - 无法在 Nodejs Typescript 应用程序中导入 URL 类

android - IONIC 2 和闪屏时间长