Created
June 12, 2014 20:10
-
-
Save kentcdodds/fa18dacf764095718bb8 to your computer and use it in GitHub Desktop.
kcdBase64
This file contains hidden or 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('app').directive('kcdBase64', function () { | |
'use strict'; | |
return { | |
restrict: 'A', | |
template: [ | |
'<span class="button file-upload-button">', | |
'<span>Select Image</span>', | |
'<input type="file" class="input-file" accept="image/*">', | |
'</span>' | |
].join(''), | |
scope: { | |
onBase64Loaded: '&kcdBase64' | |
}, | |
link: function (scope, el) { | |
el.find('input').on('change', function() { | |
if (this.files && this.files[0]) { | |
// Base64 file | |
var FR = new FileReader(); | |
FR.onload = function(e) { | |
scope.onBase64Loaded({base64:e.target.result}); | |
scope.$root.safeApply(); | |
}; | |
FR.readAsDataURL(this.files[0]); | |
} | |
}); | |
} | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment