Last active
August 29, 2015 14:22
-
-
Save hebbian/9fb51f8113d147ca4f8d to your computer and use it in GitHub Desktop.
Get Base64 image file from file input with Angular
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
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