angular2-signaturepad
Angular 2 component for szimek/signature_pad.
Install
npm install angular2-signaturepad --save
Usage example
API is identical to szimek/signature_pad.
Options are as per szimek/signature_pad with the following additions:
- canvasWidth: width of the canvas (px)
- canvasHeight: height of the canvas (px)
The above options are provided to avoid accessing the DOM directly from your component to adjust the canvas size.
import { SignaturePadModule } from 'angular2-signaturepad';
...
@NgModule({
declarations: [ ],
imports: [ SignaturePadModule ],
providers: [ ],
bootstrap: [ AppComponent ]
})
import { Component, ViewChild } from 'angular2/core';
import { SignaturePad } from 'angular2-signaturepad/signature-pad';
@Component({
template: '<signature-pad [options]="signaturePadOptions" (onBeginEvent)="drawStart()" (onEndEvent)="drawComplete()"></signature-pad>'
})
export class SignaturePadPage{
@ViewChild(SignaturePad) signaturePad: SignaturePad;
private signaturePadOptions: Object = {
'minWidth': 5,
'canvasWidth': 500,
'canvasHeight': 300
};
constructor() {
}
ngAfterViewInit() {
this.signaturePad.set('minWidth', 5);
this.signaturePad.clear();
}
drawComplete() {
console.log(this.signaturePad.toDataURL());
}
drawStart() {
console.log('begin drawing');
}
}
Demo App
https://github.com/lathonez/angular2-signaturepad-demo