Created
July 12, 2014 18:47
-
-
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.
This file contains hidden or 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
// 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