npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@danielzotti/ng-filemanager

v1.0.3

Published

It's a special angular component that replaces multiple file input. Furthermore it's completely customizable

Downloads

6

Readme

@danielzotti/ng-filemanager

Fully customizable multiple file manager for Angular with >= IE10 browser support!

Demo

Live demo on github --> https://danielzotti.github.io/ng-filemanager

How to use it

Install the package

Run npm i @danielzotti/ng-filemanager --save

Import the module

Import NgFilemanagerModule from @danielzotti/ng-filemanager in app.module.ts

import { BrowserModule } from "@angular/platform-browser";
import { NgModule } from "@angular/core";
import { FormsModule } from "@angular/forms";

import { NgFilemanagerModule } from "@danielzotti/ng-filemanager";

import { AppComponent } from "./app.component";

@NgModule({
  declarations: [AppComponent],
  imports: [BrowserModule, FormsModule, NgFilemanagerModule],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule {}

Use it in a component

Basic template

  • Easy to use
  • No validation or file size/number limitation
<form #form="ngForm" novalidate (submit)="onSubmitFiles(form)">
  <ng-filemanager [(ngModel)]="files" name="files"></ng-filemanager>
  <button>Submit</button>
</form>

Completely customizable UI and validation

validation

  • min file number min
  • max file number max
  • max total file size maxFileSize
  • disabled input when uploading isLoading
  • custom errors [exactFileNumber,minFileNumber,maxFileNumber,minFileSize]

UI

  • browse file custom text selectText
  • browse file custom icon selectIcon
  • delete all files custom text deleteAllText
  • delete all files custom icon deleteAllIcon
  • delete single file custom icom deleteIcon
<form #form="ngForm" novalidate (submit)="onSubmitFiles(form)">
  <ng-filemanager
    [(ngModel)]="files"
    name="files"
    [min]="2"
    [max]="5"
    [maxFileSize]="1024000"
    #filesRef="ngModel"
    [isLoading]="isUploadingFiles"
  >
    <ng-template #selectText>
      <span>Browse files</span>
    </ng-template>
    <ng-template #selectIcon> <i class="fa fa-files-o"></i>&nbsp; </ng-template>
    <ng-template #deleteAllIcon> <i class="fa fa-trash"></i>&nbsp; </ng-template>
    <ng-template #deleteAllText>
      <span>Delete all files</span>
    </ng-template>
    <ng-template #deleteIcon>
      <i class="fa fa-trash"></i>
    </ng-template>
  </ng-filemanager>

  <div class="error-message" *ngIf="filesRef.dirty && filesRef.errors?.exactFileNumber">
    <span>you must upload a file</span>
  </div>
  <div class="error-message" *ngIf="filesRef.dirty && filesRef.errors?.minFileNumber">
    <span>you must upload at least 2 files</span>
  </div>
  <div class="error-message" *ngIf="filesRef.dirty && filesRef.errors?.maxFileNumber">
    <span>you cannot upload more than 5 files</span>
  </div>
  <div class="error-message" *ngIf="filesRef.dirty && filesRef.errors?.maxFileSize">
    <span>you cannot upload more than 1MB</span>
  </div>

  <div class="buttons">
    <button type="submit" class="default-button" [disabled]="form.invalid || isUploadingFiles">
      Upload
      <span *ngIf="isUploadingFiles">
        (loading...)
      </span>
    </button>
    <button type="reset" class="default-button" [disabled]="isUploadingFiles" *ngIf="form.touched">
      Reset
    </button>
  </div>
</form>

Style

.ng-filemanager__container {
  // the ng-filemanager input container
}

.ng-filemanager__input {
  // the real input file (should be hidden)
  // "display: none" already set in ng-filemanager component css
}

.ng-filemanager__buttons-container {
  // "browse" and "delete all" container
}

.ng-filemanager__button {
  // "browse" and "delete all" button
}

.ng-filemanager__button__icon {
  // "browse" and "delete all" button icon
}

.ng-filemanager__file-list {
  // container of all uploaded files
}

.ng-filemanager__file {
  // single file item
}

.ng-filemanager__file__button {
  // single file "delete" button
}

.ng-filemanager__file__button__icon {
  // single file button icon
}

How to manage file upload in typescript component

onSubmitFiles(form: NgForm) {
    // manage form validation
    if (form.invalid) {
      alert('Form invalid! See console log for details');
      console.log('Form invalid', form);
      return false;
    }
    this.isUploadingFiles = true;

    const formData: FormData = new FormData();

    const files = form.value.files;

    // add other form input data to formData
    formData.append('payload', JSON.stringify({ customJsonProperty: 'customValue' }));

    // add every single file to formData
    if (typeof files !== 'undefined' && files != null && files.length > 0) {
      for (let i = 0; i < files.length; i++) {
        formData.append('file' + i, files[i].browserFile);
      }
    }
    const fakeUrl = 'https://www.mocky.io/v2/5c87748e320000d9123bd1fb';
    this.http.post(fakeUrl, formData).subscribe(res => {
      this.isUploadingFiles = false;
      alert('Done! See network details in developer console (Header of https://www.mocky.io/v2/5c87748e320000d9123bd1fb)');
      form.reset();
    });
  }