Skip to content

Instantly share code, notes, and snippets.

@boxxxie
Created March 26, 2014 16:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxxxie/9787424 to your computer and use it in GitHub Desktop.
Save boxxxie/9787424 to your computer and use it in GitHub Desktop.
image input directive
.directive('inputImage', function() {
'use strict'
return {
template: "<input type='file' accept='image/*'>",
restrict: 'E',
require: "ngModel",
link: function (scope, element, attrs, ngModel) {
element.bind('change', function (evt) {
var files = evt.target.files;
var imageFile = files[0];
var model = {
file: imageFile,
url: URL.createObjectURL(imageFile) //this is used to generate images/resize
};
scope.$apply(function(){
ngModel.$setViewValue(model);
});
});
}
};
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment