Created
March 26, 2014 16:30
-
-
Save boxxxie/9787424 to your computer and use it in GitHub Desktop.
image input directive
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
.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