diff --git a/docs/integrations/angular2.rst b/docs/integrations/angular2.rst index 053200539093..48cdfc885176 100644 --- a/docs/integrations/angular2.rst +++ b/docs/integrations/angular2.rst @@ -3,8 +3,8 @@ Angular 2 On its own, Raven.js will report any uncaught exceptions triggered from your application. For advanced usage examples of Raven.js, please read :doc:`Raven.js usage <../usage>`. -Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ExceptionHandler -`_ component. +Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ErrorHandler +`_ component. TypeScript Support @@ -54,55 +54,31 @@ First, configure SystemJS to locate the Raven.js package: } }); -Then, in your main application file (where ``bootstrap`` is called, e.g. main.ts): +Then, in your main module file (where ``@NgModule`` is called, e.g. app.module.ts): .. code-block:: js - import Raven from 'raven-js'; - import { bootstrap } from 'angular2/platform/browser'; - import { MainApp } from './app.component'; - import { provide, ExceptionHandler } from 'angular2/core'; + import Raven = require('raven-js'); + import { BrowserModule } from '@angular/platform-browser'; + import { AppComponent } from './app.component'; + import { NgModule, ErrorHandler } from 'angular2/core'; Raven .config('___PUBLIC_DSN___') .install(); - class RavenExceptionHandler { - call(err:any) { - Raven.captureException(err.originalException); + class RavenErrorHandler implements ErrorHandler { + handleError(err:any) : void { + Raven.captureException(err.originalError); } } - bootstrap(MainApp, [ - provide(ExceptionHandler, {useClass: RavenExceptionHandler}) - ]); + @NgModule({ + imports: [ BrowserModule ], + declarations: [ AppComponent ], + bootstrap: [ AppComponent ], + providers: [ {provide: ErrorHandler, useClass: RavenErrorHandler}] + }) + export class AppModule { } Once you've completed these two steps, you are done. - -Webpack, Angular CLI, and Other Module Loaders -~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - -In Webpack, Angular CLI, and other module loaders/packagers, you may need to use the **require** keyword as -part of your `import` statement: - -.. code-block:: js - - import Raven = require('raven-js'); // NOTE: "require" not "from" - import { bootstrap } from 'angular2/platform/browser'; - import { MainApp } from './app.component'; - import { provide, ExceptionHandler } from 'angular2/core'; - - Raven - .config('___PUBLIC_DSN___') - .install(); - - class RavenExceptionHandler { - call(err:any) { - Raven.captureException(err.originalException); - } - } - - bootstrap(MainApp, [ - provide(ExceptionHandler, {useClass: RavenExceptionHandler}) - ]); -