Skip to content

Commit bbd1057

Browse files
authored
Update Angular 2 docs to reflect error handler API changes (#732)
1 parent 203dd7f commit bbd1057

File tree

1 file changed

+17
-41
lines changed

1 file changed

+17
-41
lines changed

docs/integrations/angular2.rst

Lines changed: 17 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ Angular 2
33

44
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>`.
55

6-
Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ExceptionHandler
7-
<https://angular.io/docs/js/latest/api/core/index/ExceptionHandler-class.html>`_ component.
6+
Additionally, Raven.js can be configured to catch any Angular 2-specific exceptions reported through the `angular2/core/ErrorHandler
7+
<https://angular.io/docs/js/latest/api/core/index/ErrorHandler-class.html>`_ component.
88

99

1010
TypeScript Support
@@ -54,55 +54,31 @@ First, configure SystemJS to locate the Raven.js package:
5454
}
5555
});
5656
57-
Then, in your main application file (where ``bootstrap`` is called, e.g. main.ts):
57+
Then, in your main module file (where ``@NgModule`` is called, e.g. app.module.ts):
5858

5959
.. code-block:: js
6060
61-
import Raven from 'raven-js';
62-
import { bootstrap } from 'angular2/platform/browser';
63-
import { MainApp } from './app.component';
64-
import { provide, ExceptionHandler } from 'angular2/core';
61+
import Raven = require('raven-js');
62+
import { BrowserModule } from '@angular/platform-browser';
63+
import { AppComponent } from './app.component';
64+
import { NgModule, ErrorHandler } from 'angular2/core';
6565
6666
Raven
6767
.config('___PUBLIC_DSN___')
6868
.install();
6969
70-
class RavenExceptionHandler {
71-
call(err:any) {
72-
Raven.captureException(err.originalException);
70+
class RavenErrorHandler implements ErrorHandler {
71+
handleError(err:any) : void {
72+
Raven.captureException(err.originalError);
7373
}
7474
}
7575
76-
bootstrap(MainApp, [
77-
provide(ExceptionHandler, {useClass: RavenExceptionHandler})
78-
]);
76+
@NgModule({
77+
imports: [ BrowserModule ],
78+
declarations: [ AppComponent ],
79+
bootstrap: [ AppComponent ],
80+
providers: [ {provide: ErrorHandler, useClass: RavenErrorHandler}]
81+
})
82+
export class AppModule { }
7983
8084
Once you've completed these two steps, you are done.
81-
82-
Webpack, Angular CLI, and Other Module Loaders
83-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
84-
85-
In Webpack, Angular CLI, and other module loaders/packagers, you may need to use the **require** keyword as
86-
part of your `import` statement:
87-
88-
.. code-block:: js
89-
90-
import Raven = require('raven-js'); // NOTE: "require" not "from"
91-
import { bootstrap } from 'angular2/platform/browser';
92-
import { MainApp } from './app.component';
93-
import { provide, ExceptionHandler } from 'angular2/core';
94-
95-
Raven
96-
.config('___PUBLIC_DSN___')
97-
.install();
98-
99-
class RavenExceptionHandler {
100-
call(err:any) {
101-
Raven.captureException(err.originalException);
102-
}
103-
}
104-
105-
bootstrap(MainApp, [
106-
provide(ExceptionHandler, {useClass: RavenExceptionHandler})
107-
]);
108-

0 commit comments

Comments
 (0)