Created
May 12, 2015 11:18
-
-
Save 2roy999/ca2932c507e39443ca53 to your computer and use it in GitHub Desktop.
A angular directive to signature_pad
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
angular.module('SignaturePad', []) | |
.directive('SignaturePad', function () { | |
return { | |
restrict: 'A', | |
require: '?ngModel', | |
link: function (scope, element, attrs, ngModel) { | |
if (!ngModel) return; | |
var signaturePad = new SignaturePad(element[0]); | |
ngModel.$render = function () { | |
signaturePad.fromDataURL(ngModel.$viewValue) | |
}; | |
signaturePad.onEnd = function () { | |
scope.$evalAsync(read); | |
}; | |
read(); | |
function read() { | |
var dataUrl = signaturePad.toDataURL(); | |
ngModel.$setViewValue(dataUrl); | |
} | |
} | |
} | |
}) | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment