Skip to content

Instantly share code, notes, and snippets.

@carlospliego
Created July 12, 2014 18:47
Show Gist options
  • Save carlospliego/6ea25d4012e79b510407 to your computer and use it in GitHub Desktop.
Save carlospliego/6ea25d4012e79b510407 to your computer and use it in GitHub Desktop.
File Model allows you to bind <input type="file" file-model="myfile" /> to a file Object.
// Thanks http://uncorkedstudios.com/blog/multipartformdata-file-upload-with-angularjs
.directive('fileModel', ['$parse', function ($parse) {
return {
restrict: 'A',
link: function(scope, element, attrs) {
var model = $parse(attrs.fileModel);
var modelSetter = model.assign;
element.bind('change', function(){
scope.$apply(function(){
modelSetter(scope, element[0].files[0]);
});
});
}
};
}]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment