Skip to content

Instantly share code, notes, and snippets.

@mcgwiz
Created June 10, 2017 23:23
Show Gist options
  • Save mcgwiz/abcf3e67159df9ffad2d1b0a57fff377 to your computer and use it in GitHub Desktop.
Save mcgwiz/abcf3e67159df9ffad2d1b0a57fff377 to your computer and use it in GitHub Desktop.
Simple file input model binding for AngularJS
angular.module("sb", [ ]).directive('filesModel', FilesModel);
FilesModel.$inject = [ "$parse"];
function FilesModel($parse) {
return {
restrict: 'A',
link: function (scope, element, attr) {
var model = $parse(attr.filesModel);
element.on('change', function(e) {
model.assign(scope, element[0].files);
scope.$apply();
});
model.assign(scope, element[0].files);
}
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment