Skip to content

Instantly share code, notes, and snippets.

@hebbian
Last active August 29, 2015 14:22
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save hebbian/9fb51f8113d147ca4f8d to your computer and use it in GitHub Desktop.
Get Base64 image file from file input with Angular
app.directive("fileread", [function () {
return {
scope: {
fileread: "="
},
link: function (scope, element, attributes) {
element.bind("change", function (changeEvent) {
var reader = new FileReader();
reader.onload = function (loadEvent) {
scope.$apply(function () {
scope.fileread = loadEvent.target.result;
});
};
reader.readAsDataURL(changeEvent.target.files[0]);
});
}
};
}]);
<div class="form-group">
<input type="file" class="form-control" placeholder="Photo" fileread="userdata.photo">
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment