Angular Dropzone Wrapper
This is an Angular wrapper library for the Dropzone.
See a live example application here.
Building the library
npm install
npm run build
Running the example
cd example
npm install
npm start
Installing and usage
npm install ngx-dropzone-wrapper@4.7.0 --save
Load the module for your app (with global configuration):
import { DropzoneModule } from 'ngx-dropzone-wrapper';
import { DropzoneConfigInterface } from 'ngx-dropzone-wrapper';
const DROPZONE_CONFIG: DropzoneConfigInterface = {
url: 'https://httpbin.org/post',
maxFilesize: 50,
acceptedFiles: 'image/*'
};
@NgModule({
...
imports: [
...
DropzoneModule.forRoot(DROPZONE_CONFIG)
]
})
Use it in your html template (with custom configuration):
This library provides two ways to create a Dropzone element, simple component and custom directive.
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 are heavily customizing the dropzone 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]
[runInsideAngular]
(error)
(success)
(canceled)
(<dropzone-event>)
DIRECTIVE USAGE
When using only the directive you need to provide your own theming or import the default theme:
@import 'https://cdnjs.cloudflare.com/ajax/libs/dropzone/5.1.1/min/dropzone.min.css';
Dropzone directive can be used in form or div element with optional custom configuration:
<div [dropzone]="config" (error)="onUploadError($event)" (success)="onUploadSuccess($event)"></div>
[dropzone]
[disabled]
[useDropzoneClass]
[runInsideAngular]
(error)
(success)
(canceled)
(<dropzone-event>)
Available configuration options (custom / global configuration):
This library supports all Dropzone configuration options and few custom 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 Dropzone documentation.
Available control / helper functions (provided by the directive):
reset()
Above functions can be accessed through the directive reference (available as directiveRef in the component).