Skip to content

Commit 28bbddd

Browse files
authored
Add Angular 2 integration instructions (#615)
1 parent 1705c49 commit 28bbddd

File tree

3 files changed

+78
-6
lines changed

3 files changed

+78
-6
lines changed

docs/integrations/angular.rst

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
1-
AngularJS
1+
Angular 1
22
=========
33

4-
.. versionadded:: 1.3.0
5-
Prior to 1.3.0, we had an Angular plugin, but was undocumented. 1.3.0 comes with a rewritten version with better support.
6-
7-
To use Sentry with your Angular application, you will need to use both Raven.js (Sentry's browser JavaScript SDK) and the Raven.js Angular plugin.
4+
To use Sentry with your Angular 1.x application, you will need to use both Raven.js (Sentry's browser JavaScript SDK) and the Raven.js Angular plugin.
85

96
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>`.
107

118
Additionally, the Raven.js Angular plugin will catch any Angular-specific exceptions reported through Angular's ``$exceptionHandler`` interface.
129

13-
**Note**: The Angular integration supports Angular 1.x.
10+
**Note**: This documentation is for Angular 1.x. See also: :doc:`Angular 2.x <angular2>`
1411

1512
Installation
1613
------------

docs/integrations/angular2.rst

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
Angular 2
2+
=========
3+
4+
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>`.
5+
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.
8+
9+
**Note**: This document assumes you are writing your Angular 2 project in TypeScript, and using `SystemJS
10+
<https://github.com/systemjs/systemjs>`_ as your module bundler.
11+
12+
13+
TypeScript Support
14+
~~~~~~~~~~~~~~~~~~
15+
16+
Raven.js ships with a `TypeScript declaration file
17+
<https://github.com/getsentry/raven-js/blob/master/typescript/raven.d.ts>`_, which helps static checking correctness of
18+
Raven.js API calls, and facilitates auto-complete in TypeScript-aware IDEs like Visual Studio Code.
19+
20+
21+
Installation
22+
------------
23+
24+
Raven.js should be installed via npm.
25+
26+
.. code-block:: sh
27+
28+
$ npm install raven-js --save
29+
30+
31+
Configuration
32+
-------------
33+
34+
First, configure SystemJS to locate the Raven.js package:
35+
36+
.. code-block:: js
37+
38+
System.config({
39+
packages: {
40+
/* ... existing packages above ... */
41+
'raven-js': {
42+
main: 'dist/raven.js'
43+
}
44+
},
45+
paths: {
46+
/* ... existing paths above ... */
47+
'raven-js': 'node_modules/raven-js'
48+
}
49+
});
50+
51+
Then, in your main application file (where ``bootstrap`` is called, e.g. main.ts):
52+
53+
.. code-block:: js
54+
55+
import Raven from 'raven-js';
56+
import { bootstrap } from 'angular2/platform/browser';
57+
import { MainApp } from './app.component';
58+
import { provide, ExceptionHandler } from 'angular2/core';
59+
60+
Raven
61+
.config('__PUBLIC_DSN__')
62+
.install();
63+
64+
class RavenExceptionHandler {
65+
call(err:any) {
66+
Raven.captureException(err.originalException);
67+
}
68+
}
69+
70+
bootstrap(MainApp, [
71+
provide(ExceptionHandler, {useClass: RavenExceptionHandler})
72+
]);
73+
74+
Once you've completed these two steps, you are done.

docs/integrations/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ To install a plugin just include the plugin **after** Raven has been loaded and
3434
:maxdepth: 1
3535

3636
angular
37+
angular2
3738
backbone
3839
ember
3940
react

0 commit comments

Comments
 (0)