I need to dynamically change the width of signature pad. How can i do it?
<signature-pad class="signature w-50-p" id="sign_canvas" fxFlexAlign.xs="center"></signature-pad>
html:
<signature-pad fxFlex="1 1 50" (window:resize)="resizeSignaturePad()"
class="signature"
id="sign_canvas" fxFlexAlign.xs="center"></signature-pad>
ts:
resizeSignaturePad() {
this.signaturePad.set('canvasWidth', document.getElementById("sign_canvas").offsetWidth);
this.signaturePad.clear();
}
I implemented this on Angular 11 today. This answer builds on Markomar's answer. Hopefully this saves someone some headache. In short I had to manually set the canvas size using the queryPad() method because of some weird underscore. I used a template variable (#form) on an element I liked the size of and used AfterViewInit instead of OnInit so it initialized properly.
@ViewChild('form') formElement: ElementRef;
resizeSignature() {
this.signature.queryPad()._canvas.width = this.formElement?.nativeElement.offsetWidth;
}
ngAfterViewInit(): void { this.resizeSignature(); }
Try this
In your TS:
@ViewChild('signatureDiv') signatureDiv: ElementRef;
@HostListener('window:resize', ['$event'])
onResize(event) {
this.handleSignatureCanvasSize(); //handle the resizing of signature pad canvas on resizing screen
}
ngAfterViewInit() {
this.handleSignatureCanvasSize(); //handle the resizing of signature pad canvas on different screens
}
handleSignatureCanvasSize() {
//handle the resizing of signature pad canvas on resizing screen
const canvas = document.querySelector("canvas");
const tempWidth = String(this.signatureDiv.nativeElement.clientWidth);
const widthCanvas = tempWidth.concat("px");
canvas.setAttribute("width", widthCanvas);
}
In your HTML add the reference:
<div class="signature-container" #signatureDiv align="center">
<signature-pad [options]="signaturePadOptions" (onEndEvent)="drawComplete()">
</signature-pad>
</div>
You can try this:
input signature ng-model="signatureOne"></input>
<input signature ng-model="signatureTwo
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.