Last active
March 16, 2024 02:55
-
-
Save compact/8118670 to your computer and use it in GitHub Desktop.
AngularJS directive for Dropzone.js
This file contains 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
/** | |
* 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) { | |
} | |
} | |
}; | |
}); |
Nice. How do I send uploaded file along with other form inputs. I don't want instant upload
I have used AngularJS Inspinia admin template. I saw here original inspinia file dropzone not working properly. If I go other page to uploadfile page the dropzone not working. If I refreshed in that page. then dropzone working fine. Please tell me what is the issue behind that dropzone?
How is angular.forEach is better than _.each(). I prefer to use underscore.js or lodash.js.
Hi, How to add delete URL to delete the file? and Icon delete (X) is not deleting. Any help would be appreciated.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Try new AngularJS directive for Dropzone https://github.com/thatisuday/ngDropzone