|
| 1 | +# angular2-signaturepad |
| 2 | +Angular 2 component for [szimek/signature_pad](https://www.npmjs.com/package/signature_pad). |
| 3 | + |
| 4 | +<< THIS IS NO LONGER IN USE BY OWNER. PROBLEMS CAN AND DO EXIST. PRs ARE SUPER WELCOME, BUT I CAN NOT IDENTIFY WHAT YOUR ISSUES ARE, NOR WILL I CHANGE THINGS BECAUSE ANGULAR HAS CHANGED IN THE YEARS SINCE I WROTE THIS >> |
| 5 | + |
| 6 | +## Install |
| 7 | +`npm install angular2-signaturepad --save` |
| 8 | + |
| 9 | +## Reference Implementation |
| 10 | + |
| 11 | +* [Live Demo](http://lathonez.com/angular2-signaturepad-demo/) |
| 12 | +* [Source](https://github.com/lathonez/angular2-signaturepad-demo) |
| 13 | + |
| 14 | +## Usage example |
| 15 | + |
| 16 | +API is identical to [szimek/signature_pad](https://www.npmjs.com/package/signature_pad). |
| 17 | + |
| 18 | +Options are as per [szimek/signature_pad](https://www.npmjs.com/package/signature_pad) with the following additions: |
| 19 | +* canvasWidth: width of the canvas (px) |
| 20 | +* canvasHeight: height of the canvas (px) |
| 21 | +The above options are provided to avoid accessing the DOM directly from your component to adjust the canvas size. |
| 22 | + |
| 23 | +```typescript |
| 24 | + |
| 25 | +// import into app module |
| 26 | + |
| 27 | +import { SignaturePadModule } from 'angular2-signaturepad'; |
| 28 | + |
| 29 | +... |
| 30 | + |
| 31 | +@NgModule({ |
| 32 | + declarations: [ ], |
| 33 | + imports: [ SignaturePadModule ], |
| 34 | + providers: [ ], |
| 35 | + bootstrap: [ AppComponent ] |
| 36 | +}) |
| 37 | + |
| 38 | +// then import for use in a component |
| 39 | + |
| 40 | +import { Component, ViewChild } from 'angular2/core'; |
| 41 | +import { SignaturePad } from 'angular2-signaturepad/signature-pad'; |
| 42 | + |
| 43 | +@Component({ |
| 44 | + template: '<signature-pad [options]="signaturePadOptions" (onBeginEvent)="drawStart()" (onEndEvent)="drawComplete()"></signature-pad>' |
| 45 | +}) |
| 46 | + |
| 47 | +export class SignaturePadPage{ |
| 48 | + |
| 49 | + @ViewChild(SignaturePad) signaturePad: SignaturePad; |
| 50 | + |
| 51 | + private signaturePadOptions: Object = { // passed through to szimek/signature_pad constructor |
| 52 | + 'minWidth': 5, |
| 53 | + 'canvasWidth': 500, |
| 54 | + 'canvasHeight': 300 |
| 55 | + }; |
| 56 | + |
| 57 | + constructor() { |
| 58 | + // no-op |
| 59 | + } |
| 60 | + |
| 61 | + ngAfterViewInit() { |
| 62 | + // this.signaturePad is now available |
| 63 | + this.signaturePad.set('minWidth', 5); // set szimek/signature_pad options at runtime |
| 64 | + this.signaturePad.clear(); // invoke functions from szimek/signature_pad API |
| 65 | + } |
| 66 | + |
| 67 | + drawComplete() { |
| 68 | + // will be notified of szimek/signature_pad's onEnd event |
| 69 | + console.log(this.signaturePad.toDataURL()); |
| 70 | + } |
| 71 | + |
| 72 | + drawStart() { |
| 73 | + // will be notified of szimek/signature_pad's onBegin event |
| 74 | + console.log('begin drawing'); |
| 75 | + } |
| 76 | +} |
| 77 | +``` |
0 commit comments