Skip to content

Commit 1fbea7a

Browse files
committed
Merge branch 'master' of github.com:sayanee/angularjs-pdf
2 parents 639c6de + c76b1fe commit 1fbea7a

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

example/js/directives/angular-pdf.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,30 @@
102102
}
103103
};
104104

105-
PDFJS.getDocument(url, null, null, scope.onProgress).then(
106-
function(_pdfDoc) {
107-
if (typeof scope.onLoad === 'function' ) {
108-
scope.onLoad();
109-
}
110-
111-
pdfDoc = _pdfDoc;
112-
scope.renderPage(scope.pageToDisplay);
113-
114-
scope.$apply(function() {
115-
scope.pageCount = _pdfDoc.numPages;
116-
});
117-
}, function(error) {
118-
if (error) {
119-
if (typeof scope.onError === 'function') {
120-
scope.onError(error);
121-
}
122-
}
105+
function renderPDF() {
106+
if (url && url.length) {
107+
PDFJS.getDocument(url, null, null, scope.onProgress).then(
108+
function(_pdfDoc) {
109+
if (typeof scope.onLoad === 'function') {
110+
scope.onLoad();
111+
}
112+
113+
pdfDoc = _pdfDoc;
114+
scope.renderPage(scope.pageToDisplay);
115+
116+
scope.$apply(function() {
117+
scope.pageCount = _pdfDoc.numPages;
118+
});
119+
}, function(error) {
120+
if (error) {
121+
if (typeof scope.onError === 'function') {
122+
scope.onError(error);
123+
}
124+
}
125+
}
126+
);
123127
}
124-
);
128+
}
125129

126130
scope.$watch('pageNum', function(newVal) {
127131
scope.pageToDisplay = parseInt(newVal);
@@ -130,6 +134,15 @@
130134
}
131135
});
132136

137+
scope.$watch('pdfUrl', function(newVal) {
138+
if (newVal !== '') {
139+
console.log('pdfUrl value change detected: ', scope.pdfUrl);
140+
url = newVal;
141+
scope.pageToDisplay = 1;
142+
renderPDF();
143+
}
144+
});
145+
133146
}
134147
};
135148
} ]);

0 commit comments

Comments
 (0)