Skip to content

Instantly share code, notes, and snippets.

@KeithNdhlovu
Created February 13, 2017 10:24
Show Gist options
  • Save KeithNdhlovu/9a67c9cce563778d0cba67ab626a559e to your computer and use it in GitHub Desktop.
Save KeithNdhlovu/9a67c9cce563778d0cba67ab626a559e to your computer and use it in GitHub Desktop.
How to attach ng-model on an input type=file
var clientInformationApp = angular.module('clientInformationApp', [], function($interpolateProvider) {
$interpolateProvider.startSymbol('<%');
$interpolateProvider.endSymbol('%>');
}).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]);
});
}
}
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment