Created
June 10, 2017 23:23
-
-
Save mcgwiz/abcf3e67159df9ffad2d1b0a57fff377 to your computer and use it in GitHub Desktop.
Simple file input model binding for AngularJS
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
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