An Angular 4 module for simple desktop file and folder drag and drop
You can check the DEMO of the library
npm install ngx-file-drop --save
Simple usage example can be found in the sandbox folder
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { AppComponent } from './app.component';
import { FileDropModule } from 'ngx-file-drop/lib/ngx-drop';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
FormsModule,
HttpModule,
FileDropModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
import { Component } from '@angular/core';
import { FileDropModule } from 'ngx-file-drop/lib/ngx-drop';;
@Component({
selector: 'demo-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
public files: UploadFile[] = [];
public dropped(event: UploadEvent) {
this.files = event.files;
for (var file of event.files) {
file.fileEntry.file(info => {
console.log(info);
});
}
}
public fileOver(event){
console.log(event);
}
public fileLeave(event){
console.log(event);
}
}
<div class="center">
<file-drop headertext="Drop files here" (onFileDrop)="dropped($event)"
(onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)"></file-drop>
<div class="upload-table">
<table class="table">
<thead>
<tr>
<th>Name</th>
</tr>
</thead>
<tbody class="upload-name-style">
<tr *ngFor="let item of files; let i=index">
<td><strong>{{ item.relativePath }}</strong></td>
</tr>
</tbody>
</table>
</div>
</div>
Name | Description | Example |
---|---|---|
(onFileDrop) | On drop function called after the files are read | (onFileDrop)="dropped($event)" |
(onFileOver) | On drop over function | (onFileOver)="fileOver($event)" |
(onFileLeave) | On drop leave function | (onFileOver)="fileLeave($event)" |
headertext | Text to be displayed inside the drop box | headertext="Drop files here" |
customstyle | Custom style class name to be used | customstyle="my-style" |