1.4.7 • Published 4 years ago

ngx-file-up v1.4.7

Weekly downloads
8
License
ISC
Repository
-
Last release
4 years ago

NgxFileUp

File uploading plugin for AngularX applications.

Install

Run npm i ngx-file-up --save to install and save as dependency.

Import

Add import { NgxFileUpModule } from 'ngx-file-up' to your app module. Then add NgxFileUpModule to ng module imports.

Options

Directives

OptionTypeDefault ValDescription
promptstringSelect FilesPrompt message displayed before files select button
promptAllowbooleanfalseHide or show prompt message
selectBtnstringSelectThe text inside files select button
uploadBtnstringUploadThe text inside files upload button
uploadBtnAllowbooleantrueHide or show upload button
multiplebooleantrueAllow multiple files
typesstring*.*The list of allowed file types
ngxTriggerResetEventEmitterEvent received as input to trigger plugin reset

Events

EventTypeDescription
(ngxTriggerUpload)EventEmitter<FileList>Event handler to emit selected files when the "Upload" button is clicked
(ngxTriggerSelected)EventEmitter<FileList>Event handler to emit selected files when files are selected

Usage

Add this to HTML file.

<ngx-file-up></ngx-file-up>

ngxTriggerReset

app.component.html

<div>
  <ngx-file-up
    [prompt]="'Upload Files Here'"
    [promptAllow]="true"
    [selectBtn]="'Choose File(s)'"
    [uploadBtn]="'Submit'"
    [multiple]="true"
    [uploadBtnAllow]="true"
    [types]="'.pdf, .jpg, .png'"
    [ngxTriggerReset]="emitter"
  >
  </ngx-file-up>
  <br />
  <br />
  <div>This button will emit an event to remove all the selected files.</div>
  <br />
  <button class="ripple" (click)="resetFiles()" (ngxFileUpReset)="checkevent()">
    Reset Files
  </button>
</div>

app.component.ts

import { Component, EventEmitter, Output } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  @Output() emitter: EventEmitter<any> = new EventEmitter();

  constructor() { }

  resetFiles() {
    this.emitter.emit();
  }

}

Events

app.component.html

<div>
  <ngx-file-up
    [prompt]="'Upload Files Here'"
    [promptAllow]="true"
    [selectBtn]="'Choose File(s)'"
    [uploadBtn]="'Submit'"
    [multiple]="true"
    [uploadBtnAllow]="true"
    [types]="'.pdf, .jpg, .png'"
    [ngxTriggerReset]="emitter"
    (ngxTriggerSelected)="triggerOnSelected($event)"
    (ngxTriggerUpload)="triggerOnUpload($event)"
  >
  </ngx-file-up>
  <br />
  <br />
  <div>This button will emit an event to remove all the selected files.</div>
  <br />
  <button class="ripple" (click)="resetFiles()" (ngxFileUpReset)="checkevent()">
    Reset Files
  </button>
</div>

app.component.ts

import { Component, EventEmitter, Output } from '@angular/core';

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {

  @Output() emitter: EventEmitter<any> = new EventEmitter();

  constructor() { }

  // console list of files selected
  triggerOnSelected(files?: FileList) {
    console.log(files);
  }

  // console list of files selected on upload click
  triggerOnUpload(files?: FileList) {
    console.log(files);
  }

  resetFiles() {
    this.emitter.emit();
  }

}

Credit

Credit goes to "bjsawyer" for creating "mat-file-upload"

1.4.7

4 years ago

1.4.6

4 years ago

1.4.5

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.4.4

4 years ago

1.4.3

4 years ago

1.4.2

4 years ago

1.4.1

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

0.0.0

4 years ago

0.0.1

4 years ago