Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.