-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathapp.component.ts
70 lines (58 loc) · 2.43 KB
/
app.component.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import { Component, ViewChildren, QueryList, ElementRef } from '@angular/core';
import { FormBuilder, FormGroup, Validators } from '@angular/forms';
import { SignatureFieldComponent } from './signature-field/signature-field.component';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public title = 'angular2-signaturepad-demo : angular2-signaturepad@2.8.0 angular@5.1.0';
public form: FormGroup;
// for convenience as we don't have a QueryList.index
public secondSig: SignatureFieldComponent;
@ViewChildren(SignatureFieldComponent) public sigs: QueryList<SignatureFieldComponent>;
@ViewChildren('sigContainer1') public sigContainer1: QueryList<ElementRef>;
@ViewChildren('sigContainer2') public sigContainer2: QueryList<ElementRef>;
@ViewChildren('sigContainer3') public sigContainer3: QueryList<ElementRef>;
constructor(fb: FormBuilder) {
this.form = fb.group({
signatureField1: ['', Validators.required],
signatureField2: ['', Validators.required],
signatureField3: ['', Validators.required]
});
}
public ngAfterViewInit() {
this.secondSig = this.sigs.find((sig, index) => index === 1);
this.beResponsive();
this.setOptions();
}
// set the dimensions of the signature pad canvas
public beResponsive() {
console.log('Resizing signature pad canvas to suit container size');
this.size(this.sigContainer1.first, this.sigs.first);
this.size(this.sigContainer2.first, this.secondSig);
this.size(this.sigContainer3.first, this.sigs.last);
}
public size(container: ElementRef, sig: SignatureFieldComponent) {
sig.signaturePad.set('canvasWidth', container.nativeElement.clientWidth);
sig.signaturePad.set('canvasHeight', container.nativeElement.clientHeight);
}
public setOptions() {
this.sigs.first.signaturePad.set('penColor', 'rgb(255, 0, 0)');
this.secondSig.signaturePad.set('penColor', 'rgb(255, 255, 0)');
this.secondSig.signaturePad.set('backgroundColor', 'rgb(0, 0, 255)');
this.secondSig.signaturePad.clear(); // clearing is needed to set the background colour
}
public submit() {
console.log('CAPTURED SIGS:');
console.log(this.sigs.first.signature);
console.log(this.secondSig.signature);
console.log(this.sigs.last.signature);
}
public clear() {
this.sigs.first.clear();
this.secondSig.clear();
this.sigs.last.clear();
}
}