Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 17 additions & 41 deletions docs/integrations/angular2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://angular.io/docs/js/latest/api/core/index/ExceptionHandler-class.html>`_ component.
Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ErrorHandler
<https://angular.io/docs/js/latest/api/core/index/ErrorHandler-class.html>`_ component.


TypeScript Support
Expand Down Expand Up @@ -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';

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual import is import { NgModule, ErrorHandler } from "@angular/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})
]);