Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ng-input-file

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ng-input-file

A component that wraps input[type=file] element styled with Material, enables user to choose file from local device or Google drive

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

ng-input-file

npm npm License

This library provides a component input-file that wraps a legacy input[type=file] element styled with Material components, enables user to choose file from local device (supports drag-and-drop) or Google drive (needs extra setup below). This library assumes your application is already using @angular/material and one of the themes:

<!-- legacy input -->
<input type="file" accept="image/*, video/*" (change)="fileChanged($event)">

<!-- using a component -->
<input-file (files)="fileChanged($event)" #input1></input-file>

input-file component emits (files) output whenever user chooses or removes a file. By default, the component accepts image/*, video/* and you can override it by providing optional input like [accept]="'image/*'".

To support drag-and-drop, you'd need to pass in an element that will serve as a dropbox to the component:

<input-file [dropbox]="el.nativeElement"></input-file>

To enable Google drive, you'd need to import GoogleDriveService and initialize it with your developer information like below:

import { NgInputFileComponent, GoogleApiConfig, GoogleDriveService } from 'ng-input-file';

const GOOGLE_CONFIG: GoogleApiConfig = {
  developerKey: 'your-developer-key',
  appId: 'your-app-id',
  clientId: 'your-client-id'
}

export class MyComponent {

  constructor(private googleDrive: GoogleDriveService) {
    this.googleDrive.init(GOOGLE_CONFIG);
  }

A Stackblitz demo is available to show the usage.

// to install
npm install ng-input-file --save
yarn add ng-input-file

// in app.module.ts
import { NgInputFileModule } from 'ng-input-file';
@NgModule({
  imports: [
    NgInputFileModule,

// in template
<input-file (files)="fileChanged($event)" #input1></input-file>

// in component
import { NgInputFileComponent } from 'ng-input-file';

@ViewChild('input1')
private input1: NgInputFileComponent;

fileChanged({ files }) {
  console.log(`fileChanged ${files.length}`, files, this.input1.filename);
}

Keywords

FAQs

Package last updated on 22 May 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc