AngularJS service file upload
A simple service to upload a file from a given input element on demand in your controller.
HTML
<div ng-controller = "myCtrl">
<input type="file" file-model="myFile"/>
</div>
JavaScript
var myApp = angular.module('myApp', []);
myApp.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(){
console.log('CHANGE');
element.val('');
//scope.$apply(function(){
/// modelSetter(scope, element[0].files[0]);
//}); -->
});
}
};
}]);
myApp.controller('myCtrl', ['$scope', function($scope){
}]);