Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
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