Angular2 中的 Dropzone
用於 Dropzone 的 Angular 2 包裝器庫。
npm install angular2-dropzone-wrapper –save-dev
為你的 app-module 載入模組
import { DropzoneModule } from 'angular2-dropzone-wrapper';
import { DropzoneConfigInterface } from 'angular2-dropzone-wrapper';
const DROPZONE_CONFIG: DropzoneConfigInterface = {
// Change this to your upload POST address:
server: 'https://example.com/post',
maxFilesize: 10,
acceptedFiles: 'image/*'
};
@NgModule({
...
imports: [
...
DropzoneModule.forRoot(DROPZONE_CONFIG)
]
})
元件使用
只需使用 dropzone 元件替換可能會通過 Dropzone 傳遞給 Dropzone 的元素。
<dropzone [config]="config" [message]="'Click or drag images here to upload'" (error)="onUploadError($event)" (success)="onUploadSuccess($event)"></dropzone>
建立 dropzone 元件
import {Component} from '@angular/core';
@Component({
selector: 'app-new-media',
templateUrl: './dropzone.component.html',
styleUrls: ['./dropzone.component.scss']
})
export class DropZoneComponent {
onUploadError(args: any) {
console.log('onUploadError:', args);
}
onUploadSuccess(args: any) {
console.log('onUploadSuccess:', args);
}
}