//0. Add a ref to the rootcause-script at the start of the body tag
//1. Add an errorHandler.ts file:
import { ErrorHandler } from '@angular/core';
declare const RC:any;
const logger = new RC.Logger({
applicationId : 'afc94d273a39ecb7501ef8d39f031099',
recordUserActions : true,
recordSessionVideo : true,
logResourceLoadFailures : true,
logAjaxRequests : true,
captureScreenshot : true,
frameworkVersion : 'Angular 2',
user : {
name : 'Dan Anderson',
email : 'demouser@therootcause.io',
imgUrl : 'https://s.gravatar.com/avatar/0b9e04aed9dcc2d3a121522147dfc7fa?s=80'
}
});
export default class MyErrorHandler implements ErrorHandler {
handleError(error) {
logger.logException(error);
console.error(error);
}
}
//2. Use this from the main app:
import 'hammerjs';
import { ErrorHandler, NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { FormsModule } from '@angular/forms';
import { AppMaterialModule } from './app.material.module';
import { AppComponent, DialogContentComponent } from './app.component';
import MyErrorHandler from './errorHandler';
@NgModule({
imports: [
BrowserModule,
FormsModule,
AppMaterialModule,
BrowserAnimationsModule
],
declarations: [AppComponent, DialogContentComponent],
entryComponents: [DialogContentComponent],
bootstrap: [AppComponent],
// ********* HERE!
providers: [{ provide: ErrorHandler, useClass: MyErrorHandler }]
// *********
})
export class AppModule { }
Angular 5 Material sample app, click the bug icon below to trigger an error.
SHOW CODE