1.2.0 • Published 4 months ago

ng-dropfile v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
4 months ago

ng-dropfile

An easy-to-use and customizable Angular component for handling files with style.

  • Advanced features
  • Customizable
  • Image preview
  • File deletion
  • Multiple event triggers

Installation

Install ng-dropfile package with npm

  npm install ng-dropfile

Setup

Import the ngDropfileModule in your application.

import { CommonModule } from '@angular/common';
import { NgDropfileModule } from 'ng-dropfile';

@NgModule({
  imports: [
    CommonModule,
    NgDropfileModule,
  ],
  bootstrap: [...],
  declarations: [...],
})
class MainModule {}

Usage/Examples

Create the directive where you need it:

<ng-dropfile></ng-dropfile>

You can customize your dropfile properties directly. In this example, we change the default maxFileSize from 1MB to 5MB.

<ng-dropfile [maxFileSize]="5"></ng-dropfile>

This is how you can change the default messages for the component:

<ng-dropfile [messages]=:'Drag and Drop your files'}"></ng-dropfile>

You also can capture the emmited events:

<ng-dropfile (onClear)="myFunction($event)"></ng-dropfile>

Options

Individual customizable options.

OptionDescriptionTypeDefault Value
maxFileSizeMaximum file size in megabytes.number1
multipleAllow multiple file selection.booleantrue
showErrorsShow or hide error messages.booleantrue
showFileListShow or hide the list of selected files.booleantrue
formatsAcceptedAccepted file formats.string[]'png', 'jpg', 'jpeg', 'gif', 'pdf'
messagesCustom messages for the user interface.object
     buttonDefault message to browse button.stringBrowse file
     defaultDefault message to select file.stringChoose a file or drag and drop it here
     formatsDefault message for accepted formats/extensions.stringOnly \<formats> formats accepted.
     defaultDefault message to replace file.stringClick to replace
errorsPossible error messages.object
     defaultDefault error messagestringOoops; something wrong happened.
     filesizeDefault error message for file size.stringSome files are too big. Max file size: \<maxFileSize> MB.
     formatsDefault message to replace file.stringSome files don't match the valid formats.

Events

EventDescriptionResponse
onDeleteTriggered when a file is deleted or removed.File
onSelectTriggered when one or more files are selected.File[]
onErrorTriggered when an error occurs.string
onClearTriggered when the component is reset or cleared.void

Methods

EventDescriptionEvent Type
getFilesGet the selected files.File[]
clearClear all selected files.void

You can call a dropfile child component method assigning a #id in your <ng-dropfile> tag in your html:

<ng-dropfile #dropfileChild ></ng-dropfile>

And access it in your parent component in this way:

export class MyComponent {

 constructor(){ }

@ViewChild(DropfileComponent) dropfileChild: DropfileComponent;

myClearFunction(){
    this.dropfileChild.clear();
  }
}

License

MIT

Authors