Skip to content

Commit 23e7bd5

Browse files
committed
feature: handle error
1 parent 341688e commit 23e7bd5

File tree

5 files changed

+41
-21
lines changed

5 files changed

+41
-21
lines changed

dist/angular-pdf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@
9696
});
9797
}, function(error) {
9898
if (error) {
99-
console.log('ERROR in getting document: ' + error);
99+
if (typeof scope.onError === 'function') {
100+
scope.onError(error);
101+
}
100102
}
101103
}
102104
);

dist/angular-pdf.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/js/controllers/docCtrl.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
app.controller('DocCtrl', function($scope) {
22

33
$scope.pdfName = 'Relativity: The Special and General Theory by Albert Einstein';
4-
$scope.pdfUrl = 'pdf/relativity.pdf';
4+
$scope.pdfUrl = 'pdf/relatiity.pdf';
55
$scope.scroll = 0;
66

77
$scope.getNavStyle = function(scroll) {
88
if(scroll > 100) return 'pdf-controls fixed';
99
else return 'pdf-controls';
1010
}
1111

12+
$scope.onError = function(error) {
13+
console.log(error);
14+
}
15+
1216
});

example/js/directives/angular-pdf.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@
9696
});
9797
}, function(error) {
9898
if (error) {
99-
console.log('ERROR in getting document: ' + error);
99+
if (typeof scope.onError === 'function') {
100+
scope.onError(error);
101+
}
100102
}
101103
}
102104
);

readme.md

+29-17
Original file line numberDiff line numberDiff line change
@@ -21,46 +21,47 @@ Check [`bower.json` file](https://github.com/sayanee/angularjs-pdf/blob/master/b
2121
###Features
2222

2323
1. next / previous page
24-
1. zoom in / out
25-
1. rotate clockwise
26-
1. jump to a page number
27-
1. when scrolling, the pdf controls will get fixed position at the top
28-
1. define the view template
29-
1. define the path to pdf with scope variable
24+
- zoom in / out
25+
- rotate clockwise
26+
- jump to a page number
27+
- when scrolling, the pdf controls will get fixed position at the top
28+
- define the view template
29+
- define the path to pdf with scope variable
30+
- handles error
3031

3132
## Getting Started
3233

3334
1. install or copy over the file `dist/angular-pdf.min.js` or `dist/angular-pdf.js`
3435

35-
```
36+
```shell
3637
bower install angular-pdf
3738
```
3839
1. include the path to the direcitve file in `index.html`
3940

40-
```
41+
```html
4142
<script src="js/vendor/angular-pdf/dist/angular-pdf.js"></script>
4243
```
4344

4445
1. include the directive as a dependency when defining the angular app:
4546

46-
```
47+
```js
4748
var app = angular.module('App', ['pdf']);
4849
```
4950
1. include the directive with the attribute path to the partial under a controller
5051

51-
```
52+
```html
5253
<div class="wrapper" ng-controller="DocCtrl">
5354
<ng-pdf template-url="/partials/viewer.html"></ng-pdf>
5455
</div>
5556
```
5657
1. include the `canvas` element to display the pdf in the template-url file
5758

58-
```
59+
```html
5960
<canvas id="pdf-canvas"></canvas>
6061
```
6162
1. include the path to the pdf file in the controller
6263

63-
```
64+
```js
6465
app.controller('DocCtrl', function($scope) {
6566
$scope.pdfUrl = '/pdf/relativity.pdf';
6667
});
@@ -82,41 +83,52 @@ Check [`bower.json` file](https://github.com/sayanee/angularjs-pdf/blob/master/b
8283
```
8384
1. **Rotate clockwise**: Include the controls in the view file as defined in the attribute `template-url` and the initial class `rotate0`
8485
85-
```
86+
```html
8687
<button ng-click="rotate()">90</span></button>
8788
...
8889
<canvas id="pdf-canvas" class="rotate0"></canvas>
8990
```
9091
9192
include the css styles:
9293
93-
```
94+
```css
9495
.rotate0 {-webkit-transform: rotate(0deg); transform: rotate(0deg); }
9596
.rotate90 {-webkit-transform: rotate(90deg); transform: rotate(90deg); }
9697
.rotate180 {-webkit-transform: rotate(180deg); transform: rotate(180deg); }
9798
.rotate270 {-webkit-transform: rotate(270deg); transform: rotate(270deg); }
9899
```
99100
1. **Jump to page number**: Include the controls in the view file as defined in the attribute `template-url`
100101
101-
```
102+
```html
102103
<span>Page: </span><input type="text" min=1 ng-model="pageNum"><span> / {{pageCount}}</span>
103104
```
104105
1. **Fixed pdf controls upon scrolling**: Wrap the controls in the view file as defined in the attribute `template-url` with a tag `nav` with an `ng-class`. Amend the scroll amount as required.
105106
106-
```
107+
```html
107108
<nav ng-class="{'pdf-controls fixed': scroll > 100, 'pdf-controls': scroll <= 100}">
108109
...
109110
</nav>
110111
```
111112
112113
And include the relevant css styles as required:
113114
114-
```
115+
```css
115116
.pdf-controls { width: 100%; display: block; background: #eee; padding: 1em;}
116117
.fixed { position: fixed; top: 0; left: calc(50% - 480px); z-index: 100; width: 100%; padding: 1em; background: rgba(238, 238, 238,.9); width: 960px; }
117118
```
118119
1. open the file `index.html` with a web server
119120
121+
###Handle error
122+
123+
1. in the controller, you can call the function `$scope.onError`:
124+
125+
```js
126+
$scope.onError = function(error) {
127+
// handle the error
128+
// console.log(error);
129+
}
130+
```
131+
120132
##Variations
121133
122134
1. If using with [Angular UI modal](http://angular-ui.github.io/bootstrap/#/modal), `pageNum` attribute is no longer required. [Checkout the implementation](https://github.com/sayanee/angularjs-pdf/issues/12)

0 commit comments

Comments
 (0)