tree: 29507abf38a537a4649cf4c03423b8cdb72f3c51 [path history] [tgz]
  1. file-input.component.d.ts
  2. file-input.component.scss
  3. README.md
node_modules/@covalent/core/file/file-input/README.md

TdFileInputComponent: td-file-input

Usage

Add the element wherever you want to bind a [File | FileList] into a class model without additional elements.

Can also drop a file(s) into the component to bind the file(s) to it.

Example for usage:

<td-file-input [(ngModel)]="files" color="primary" (select)="selectEvent($event)"
               accept=".ext,.anotherExt" [disabled]="disabled" multiple>
  <mat-icon>attach_file</mat-icon><span>Choose a file...</span>
</td-file-input>
export class Demo {

  files: File | FileList;
  disabled: boolean = false;

  selectEvent(files: FileList | File): void {
    if (files instanceof FileList) {
      ...
    } else {
      ...
    }
  };
} 

API Summary

Inputs

  • color: string
    • Sets button color. Uses same color palette accepted as [MatButton].
  • multiple: boolean
    • Sets if multiple files can be dropped/selected at once in [TdFileUploadComponent].
  • accept: string
    • Sets files accepted when opening the file browser dialog. Same as “accept” attribute in <input/> element.
  • disabled: boolean
    • Disables [TdFileUploadComponent] and clears selected/dropped files.

Events

  • select: function($event)
    • Event emitted when a file is selected.
    • Emits a [File or FileList] object.

Methods

  • clear: function
    • Used to clear the selected files from the [TdFileInputComponent].

Setup

Import the [CovalentFileModule] in your NgModule:

import { CovalentFileModule } from '@covalent/core/file';
@NgModule({
  imports: [
    CovalentFileModule,
    ...
  ],
  ...
})
export class MyModule {}

TdFileSelectDirective: tdFileSelect

Usage

Add the directive wherever you want to bind a [File | FileList] into a class model to an existing element.

Uses optional [(ngModel)] directive to bind file. (if [(ngModel]) exists, [fileSelect] is omitted)

Example for usage:

<input type="file" tdFileSelect (fileSelect)="files = $event" multiple>

API Summary

Inputs

  • multiple: boolean
    • Sets whether multiple files can be selected at once in host element, or just a single file.
    • Can also be “multiple” native attribute.

Events

  • fileSelect: function($event)
    • Event emitted when a file or files are selected in host [HTMLInputElement].
    • Emits a [FileList or File] object. Alternative to not use [(ngModel)].

TdFileDropDirective: tdFileDrop

Usage

Add the directive wherever you want to add drop support to an element to bind a [File | FileList] into a class model.

To add effect when ondragenter event is executed, override .drop-zone class in the context you are using it.

Note: if element has child elements, add * { pointer-events: none; } to avoid event being thrown again while navigating in child elements.

Example for usage:

<div tdFileDrop (fileDrop)="files = $event" multiple [disabled]="disabled">
</div> 

API Summary

Inputs

  • multiple: boolean
    • Sets whether multiple files can be dropped at once in host element, or just a single file.
    • Can also be “multiple” native attribute.
  • disabled: boolean
    • Disabled drop events for host element.

Events

  • fileDrop: function($event)
    • Event emitted when a file or files are dropped in host element after being validated.
    • Emits a [FileList or File] object.