Angular Dropzone Wrapper
This is an Angular wrapper library for the Dropzone. To use this library you should get familiar with the Dropzone documentation as well since this documentation only explains details specific to this wrapper.
This documentation is for the latest 6.x.x version which requires Angular 5 or newer. For Angular 4 you need to use the latest 4.x.x version. Documentation for the 4.x.x can be found from here.
Quick links
Example application
|
StackBlitz example
|
Dropzone documentation
Building the library
npm install
npm run build
Running the example
npm install
npm run start
Installing and usage
npm install ngx-dropzone-wrapper --save
Load the module for your app (with global configuration):
Providing the global configuration is optional and when used you should only provide the configuration in your root module.
import { DropzoneModule } from 'ngx-dropzone-wrapper';
import { DROPZONE_CONFIG } from 'ngx-dropzone-wrapper';
import { DropzoneConfigInterface } from 'ngx-dropzone-wrapper';
const DEFAULT_DROPZONE_CONFIG: DropzoneConfigInterface = {
url: 'https://httpbin.org/post',
maxFilesize: 50,
acceptedFiles: 'image/*'
};
@NgModule({
...
imports: [
...
DropzoneModule
],
providers: [
{
provide: DROPZONE_CONFIG,
useValue: DEFAULT_DROPZONE_CONFIG
}
]
})
Use it in your HTML template (with custom configuration):
This library provides two ways to create a Dropzone element, component for simple use cases and directive for more custom use cases.
COMPONENT USAGE
Simply replace the element that would ordinarily be passed to Dropzone
with the dropzone component.
NOTE: Component provides couple additional features from directive such as the placeholder image. If you don't need them or want to create custom component then you might want to use the directive instead.
<dropzone [config]="config" [message]="'Click or drag images here to upload'" (error)="onUploadError($event)" (success)="onUploadSuccess($event)"></dropzone>
[config]
[disabled]
[message]
[placeholder]
[useDropzoneClass]
(error)
(success)
(canceled)
(<dropzoneEvent>)
DIRECTIVE USAGE
When using only the directive you need to provide your own theming or import the default theme:
@import '~dropzone/dist/min/dropzone.min.css';
Dropzone directive can be used in form or div element with optional custom configuration:
<div class="dropzone" [dropzone]="config" (error)="onUploadError($event)" (success)="onUploadSuccess($event)"></div>
[dropzone]
[disabled]
(error)
(success)
(canceled)
(<dropzoneEvent>)
Available configuration options (custom / global configuration):
This library supports all Dropzone configuration options and few extra options for easier usage.
LIBRARY OPTIONS
autoReset
errorReset
cancelReset
DROPZONE OPTIONS
url
method
headers
paramName
maxFilesize
acceptedFiles
For more detailed documentation with all the supported Dropzone events / options see the Dropzone documentation.
Available control / helper functions (provided by the directive):
dropzone()
reset(cancel?)
Above functions can be accessed through the directive reference (available as directiveRef in the component).