[ Angular ] ng-file-upload

angular.module('whatever.module.it.is', ['ngFileUpload'])

.directive('whateverDirective', function(){

return {

restrict: 'E',
controllerAs: 'ctrl',

controller: ['Upload', function(Upload) {

this.uploadFunction = function(file){

return Upload.upload({method: 'POST',

url: '/api/whatever_endpoint',

data: {

file: file,

whatever_param: whatever_value

}

}).success(function(response){

console.log(response.fileUrl);

});

}

}

})

<whatever-directive>
<div class="button" ngf-select="ctrl.uploadFunction($file)" ngf-accept="'.js'">Upload on file select</div>
</whatever-directive>

ref : https://github.com/danialfarid/ng-file-upload

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s