Skip to content

Commit 1cf1351

Browse files
committed
Merge pull request #486 from getsentry/angular-docs
Update documentation for Angular plugin
2 parents 27ab9fe + 9b34edb commit 1cf1351

File tree

1 file changed

+87
-20
lines changed

1 file changed

+87
-20
lines changed

docs/integrations/angular.rst

Lines changed: 87 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,44 +4,111 @@ AngularJS
44
.. versionadded:: 1.3.0
55
Prior to 1.3.0, we had an Angular plugin, but was undocumented. 1.3.0 comes with a rewritten version with better support.
66

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.
8+
9+
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>`.
10+
11+
Additionally, the Raven.js Angular plugin will catch any Angular-specific exceptions reported through Angular's ``$exceptionHandler`` interface.
12+
13+
**Note**: The Angular integration supports Angular 1.x.
14+
715
Installation
816
------------
917

10-
Start by adding the ``raven.js`` script tag to your page. It should go **before** your application code.
18+
Raven.js and the Raven.js Angular plugin are distributed using a few different methods.
19+
20+
Using our CDN
21+
~~~~~~~~~~~~~
22+
23+
For convenience, our CDN serves a single, minified JavaScript file containing both Raven.js and the Raven.js Angular plugin. It should be included **after** Angular, but **before** your application code.
1124

1225
Example:
1326

1427
.. sourcecode:: html
1528

29+
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script>
1630
<script src="https://cdn.ravenjs.com/2.1.0/angular/raven.min.js"></script>
31+
<script>Raven.config('___PUBLIC_DSN___').install();</script>
1732

18-
<!-- your application code below -->
19-
<script src="static/app.js"></script>
33+
Note that this CDN build auto-initializes the Angular plugin.
2034

21-
Additionally, inside your main Angular application module, you need to declare ``ngRaven`` as a
22-
module dependency:
35+
Using package managers
36+
~~~~~~~~~~~~~~~~~~~~~~
2337

24-
.. code-block:: javascript
38+
Pre-built distributions of Raven.js and the Raven.js Angular plugin are avilable via both Bower and npm.
2539

26-
var myApp = angular.module('myApp', [
27-
'ngRaven',
28-
'ngRoute',
29-
'myAppControllers',
30-
'myAppFilters'
31-
]);
40+
Bower
41+
`````
42+
43+
.. code
3244
33-
Configuring the Client
34-
----------------------
45+
.. code-block:: sh
3546
36-
While adding ``ngRaven`` to your app will capture enable integration support, you'll still need
37-
to wire up the SDK just as if you weren't using Angular. This should happen immediately **after** the JS SDK script tag:
47+
$ bower install raven-js --save
3848
3949
.. code-block:: html
4050

41-
<script src="https://cdn.ravenjs.com/2.1.0/angular/raven.min.js"></script>
51+
<script src="/bower_components/angular/angular.js"></script>
52+
<script src="/bower_components/raven-js/dist/raven.js"></script>
53+
<script src="/bower_components/raven-js/dist/plugins/angular.js"></script>
54+
<script>
55+
Raven
56+
.config('___PUBLIC_DSN___')
57+
.addPlugin(Raven.Plugins.Angular)
58+
.install();
59+
</script>
60+
npm
61+
````
62+
63+
.. code-block:: sh
64+
65+
$ npm install raven-js --save
66+
67+
.. code-block:: html
68+
69+
<script src="/node_modules/angular/angular.js"></script>
70+
<script src="/node_modules/raven-js/dist/raven.js"></script>
71+
<script src="/node_modules/raven-js/dist/plugins/angular.js"></script>
4272
<script>
43-
Raven.config('___PUBLIC_DSN___').install();
73+
Raven
74+
.config('___PUBLIC_DSN___')
75+
.addPlugin(Raven.Plugins.Angular)
76+
.install();
4477
</script>
4578

46-
At this point the SDK will capture Angular-specific errors, as well as general JavaScript
47-
issues that may happen outside of the scope of the framework.
79+
These examples assume that Angular is exported globally as `window.angular`. You can alternatively pass a reference to the `angular` object directly as the second argument to `addPlugin`:
80+
81+
.. code-block:: javascript
82+
83+
Raven.addPlugin(Raven.Plugins.Angular, angular);
84+
85+
Module loaders (CommonJS)
86+
~~~~~~~~~~~~~~~~~~~~~~~~~
87+
88+
Raven and the Raven Angular plugin can be loaded using a module loader like Browserify or Webpack.
89+
90+
.. code-block:: javascript
91+
92+
var angular = require('angular');
93+
var Raven = require('raven-js');
94+
95+
Raven
96+
.config('___PUBLIC_DSN___')
97+
.addPlugin(require('raven-js/plugins/angular'), angular)
98+
.install();
99+
100+
Note that when using CommonJS-style imports, you must pass a reference to the `angular` as the second argument to `addPlugin`.
101+
102+
Angular Configuration
103+
---------------------
104+
105+
Inside your main Angular application module, you need to declare `ngRaven` as a module dependency:
106+
107+
.. code-block:: javascript
108+
109+
var myApp = angular.module('myApp', [
110+
'ngRaven',
111+
'ngRoute',
112+
'myAppControllers',
113+
'myAppFilters'
114+
]);

0 commit comments

Comments
 (0)