Created
July 6, 2015 04:19
-
-
Save Kimserey/567330d3fc9cf91d75a3 to your computer and use it in GitHub Desktop.
Simple file upload directive in angularjs
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
(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