1.0.4 • Published 2 years ago

ngx-mat-file v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

File input component for Angular Material

Description

  • Preview option
  • Drag & Drop support
  • Can be used with both reactive and template driven forms
  • Validators, like required, min, max-length and file size
  • Works within mat-form-field

Demo

Stackblitz

Demo

Install

Install ngx-mat-file

npm i ngx-mat-file

API Reference

import { NgxMatFileModule } from 'ngx-mat-file';

@NgModule({
  imports: [ NgxMatFileModule ]
})

Selector: ngx-mat-file

Properties

NameTypeDefaultDescription
@Input() requiredbooleanfalseWhether the component is required.
@Input() multiplebooleanfalseAllows multiple file selection.
@Input() acceptstringemptyAccepting file types.
@Input() previewbooleantrueEnable image preview.
@Input() previewWidthstring \| number200pxSize of preview in pixels.
@Input() hiddenUploadbooleanfalseHide or show Upload button.
@Input() minlengthnumber1Minimum number of files.
@Input() maxlengthnumber3Maximum number of files.
@Input() maxFileSizenumber5Maximum file size in megabytes.
@Input() buttonVariantstringmat-flat-buttonButton style.
@Input() buttonBrowseTextstringBrowseLabel of browse button
@Input() buttonUploadTextstringUploadLabel of upload button
@Input() buttonRemoveAllTextstringRemove AllLabel of remove all button
@Input() dragAndDropTextstringDrag & drop files hereLabel of dropzone
@Input() invalidMinFileCountMessagestringMinimum {0} file(s) requiredCustom error message
@Input() invalidMaxFileCountMessagestringMaximum number of files exceededCustom error message
@Input() invalidFileTypeMessagestringInvalid file type. Allowed file types: {0}Custom error message
@Input() invalidFileSizeMessagestringMaximum size: {0} MBCustom error message
@Output() onUploadClickEventEmitter<any>-Event emitted when upload button clicked.

Usage

Template driven

<mat-form-field appearance="outline">
  <ngx-mat-file
    [required]=true
    [multiple]=false
    [minlength]=2
    [maxlength]=5
    [maxFileSize]=10
    (onUploadClick)="yourUploadFunction(files)"
    [(ngModel)]="files"
    name="fileInput">
  </ngx-mat-file>
</mat-form-field>

Reactive

<mat-form-field appearance="outline">
  <ngx-mat-file
    [required]=true
    accept="image/*"
    [minlength]="3" 
    [multiple]="true"
    [preview]="true"
    [hiddenUpload]="true"
    previewWidth=100
    formControlName="files">
  </ngx-mat-file>
</mat-form-field>

License

MIT

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago

0.1.7

2 years ago

0.1.6

2 years ago

0.1.5

2 years ago

0.0.3

2 years ago

0.0.0

2 years ago

0.1.4

2 years ago

0.1.3

2 years ago

0.1.2

2 years ago

0.1.1

2 years ago

0.1.0

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago