Skip to content

Commit

Permalink
Merge pull request #47 from ghetolay/loadoutput
Browse files Browse the repository at this point in the history
Use @output for after load events
  • Loading branch information
VadimDez authored Jan 23, 2017
2 parents a532a50 + 952bdf3 commit b5f78af
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"pdfjs-dist": "^1.6.329"
},
"dependencies": {
"@types/pdf": "0.0.31",
"pdfjs-dist": "^1.6.329"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/app/app.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
[rotation]="rotation"
[original-size]="originalSize"
[show-all]="showAll"
[after-load-complete]="afterLoadComplete"
(after-load-complete])="afterLoadComplete($event)"
[zoom]="zoom"
[render-text]="renderText"
></pdf-viewer>
Expand Down
6 changes: 1 addition & 5 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ export class AppComponent {
pdf: any;
renderText: boolean = true;

constructor() {
this.afterLoadComplete = this.afterLoadComplete.bind(this);
}

incrementPage(amount: number) {
this.page += amount;
}
Expand Down Expand Up @@ -67,7 +63,7 @@ export class AppComponent {
* Get pdf information after it's loaded
* @param pdf
*/
afterLoadComplete(pdf: any) {
afterLoadComplete(pdf: PDFDocumentProxy) {
this.pdf = pdf;
}
}
13 changes: 5 additions & 8 deletions src/pdf-viewer/pdf-viewer.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import 'pdfjs-dist/build/pdf.combined';
`]
})

export class PdfViewerComponent extends OnInit {
export class PdfViewerComponent implements OnInit {
private _showAll: boolean = false;
private _renderText: boolean = true;
private _originalSize: boolean = true;
Expand All @@ -38,11 +38,10 @@ export class PdfViewerComponent extends OnInit {
private _rotation: number = 0;
private isInitialised: boolean = false;
private lastLoaded: string;
@Input('after-load-complete') afterLoadComplete: Function;

constructor(private element: ElementRef) {
super();
}
@Output('after-load-complete') afterLoadComplete = new EventEmitter<PDFDocumentProxy>();

constructor(private element: ElementRef) { }

ngOnInit() {
this.main();
Expand Down Expand Up @@ -152,9 +151,7 @@ export class PdfViewerComponent extends OnInit {
this._pdf = pdf;
this.lastLoaded = src;

if (this.afterLoadComplete && typeof this.afterLoadComplete === 'function') {
this.afterLoadComplete(pdf);
}
this.afterLoadComplete.emit(pdf);

this.onRender();
});
Expand Down

0 comments on commit b5f78af

Please sign in to comment.