Skip to content

Instantly share code, notes, and snippets.

@adriancbo
Forked from compact/dropzone-directive.js
Created October 13, 2015 01:44
Show Gist options
  • Save adriancbo/1d4c898693bb572e5717 to your computer and use it in GitHub Desktop.
Save adriancbo/1d4c898693bb572e5717 to your computer and use it in GitHub Desktop.
AngularJS directive for Dropzone.js
/**
* An AngularJS directive for Dropzone.js, http://www.dropzonejs.com/
*
* Usage:
*
* <div ng-app="app" ng-controller="SomeCtrl">
* <button dropzone="dropzoneConfig">
* Drag and drop files here or click to upload
* </button>
* </div>
*/
angular.module('dropzone', []).directive('dropzone', function () {
return function (scope, element, attrs) {
var config, dropzone;
config = scope[attrs.dropzone];
// create a Dropzone for the element with the given options
dropzone = new Dropzone(element[0], config.options);
// bind the given event handlers
angular.forEach(config.eventHandlers, function (handler, event) {
dropzone.on(event, handler);
});
};
});
angular.module('app', ['dropzone']);
angular.module('app').controller('SomeCtrl', function ($scope) {
$scope.dropzoneConfig = {
'options': { // passed into the Dropzone constructor
'url': 'upload.php'
},
'eventHandlers': {
'sending': function (file, xhr, formData) {
},
'success': function (file, response) {
}
}
};
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment