Skip to content

Commit 91a5631

Browse files
committed
update Angular demo with exceptionHandler
1 parent 9e6a7dd commit 91a5631

2 files changed

Lines changed: 20 additions & 8 deletions

File tree

demo/demo-angular.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
<!doctype html>
22
<html ng-app="demoApp">
33
<head>
4+
<script src="../node_modules/stacktrace-js/dist/stacktrace-with-promises-and-json-polyfills.js"></script>
5+
<script src="../stackdriver-errors.js"></script>
46
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.0-rc.2/angular.min.js"></script>
57
<script src="demo-angular.js"></script>
68
</head>
79
<body>
8-
<h2>Todo</h2>
10+
<h2>Angular App</h2>
911
<div ng-controller="DemoController as demo">
10-
<form ng-submit="demo.triggerCrash()">
11-
<input type="text" ng-model="demo.customText" size="30"
12-
placeholder="add custom text here">
12+
<form ng-submit="demo.starUser()">
1313
<input class="btn-primary" type="submit" value="Crash">
1414
</form>
1515
</div>

demo/demo-angular.js

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,21 @@
11
angular.module('demoApp', [])
2+
3+
.factory('$exceptionHandler', ['$log', '$window', function($log, $window) {
4+
var StackdriverErrors = new $window.StackdriverErrorReporter();
5+
StackdriverErrors.start({
6+
projectId: '<your-project-id>',
7+
key: '<your-api-key>'
8+
});
9+
10+
return function(exception, cause) {
11+
StackdriverErrors.report(exception);
12+
$log.warn('Reported error:', exception, cause);
13+
};
14+
}])
15+
216
.controller('DemoController', function() {
317
var demo = this;
4-
demo.customText = '';
5-
6-
demo.triggerCrash = function() {
7-
console.log('crash', demo.customText);
18+
demo.starUser = function() {
19+
demo.user.star();
820
};
921
});

0 commit comments

Comments
 (0)