Skip to content

Instantly share code, notes, and snippets.

@Kimserey
Created July 6, 2015 04:19
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 Kimserey/567330d3fc9cf91d75a3 to your computer and use it in GitHub Desktop.
Save Kimserey/567330d3fc9cf91d75a3 to your computer and use it in GitHub Desktop.
Simple file upload directive in angularjs
(function () {
'use strict';
angular
.module('app')
.directive('myPhoto', myPhoto);
function myPhoto() {
var directive = {
link: link,
restrict: 'A',
scope: {
photo: '=myPhoto'
}
};
return directive;
function link(scope, element, attrs) {
element.bind('change', function () {
scope.$apply(function () {
if (element[0].files && element[0].files.length > 0) {
scope.photo = element[0].files[0];
}
});
});
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment