Last active
March 21, 2017 02:16
-
-
Save martianyi/420c56ec710a9daf58b7 to your computer and use it in GitHub Desktop.
angularjs directive to upload file
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
var fileModel = angular.module('directives.fileModel', []); | |
fileModel.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