# ng2-file-required

> Angular input file required directive

Latest version **1.0.11** (published 2018-08-19) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install ng2-file-required
pnpm add ng2-file-required
yarn add ng2-file-required
bun add ng2-file-required
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.11 |
| Published | 2018-08-19 |
| First published | 2017-04-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 116.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Maintainers | pkantsedalov |
| Keywords | angular2, angularjs, input, file, required, directive, validation, angular-file-required, angular-file-validation |

## Links

- npm: https://www.npmjs.com/package/ng2-file-required
- Repository: https://github.com/pkantsedalov/ng2-file-required
- Homepage: https://github.com/pkantsedalov/ng2-file-required#readme
- Issues: https://github.com/pkantsedalov/ng2-file-required/issues
- npm.io page: https://npm.io/package/ng2-file-required

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 1.0.11 (latest) — 2018-08-19
- 1.0.13 — 2018-08-19
- 1.0.12 — 2018-08-19
- 1.0.10 — 2017-07-07
- 1.0.9 — 2017-07-07
- 1.0.8 — 2017-07-07
- 1.0.7 — 2017-07-07
- 1.0.6 — 2017-07-07
- 1.0.5 — 2017-07-07
- 1.0.4 — 2017-07-07
- 1.0.3 — 2017-07-07
- 1.0.2 — 2017-07-07
- 1.0.1 — 2017-05-29
- 1.0.0 — 2017-05-28
- 0.0.0-beta.6 — 2017-05-25
- … 5 more at https://npm.io/package/ng2-file-required/versions

## README

# ng2-file-required [![npm version](https://badge.fury.io/js/ng2-file-required.svg)](http://badge.fury.io/js/ng2-file-required) [![npm downloads](https://img.shields.io/npm/dm/ng2-file-required.svg)](https://npmjs.org/ng2-file-required)

### @DEPRACATED: the project is not maintainable anymore because of moving to the newest angular version. Use [ngx-file-required](https://npmjs.org/package/ngx-file-required) instead.

[![Build Status](https://travis-ci.org/pkantsedalov/ng2-file-required.svg?branch=master)](https://travis-ci.org/pkantsedalov/ng2-file-required)

<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
**Table of Contents**  *generated with [DocToc](https://github.com/thlorenz/doctoc)*

  - [Description](#description)
  - [Installation](#installation)
  - [Usage](#usage)
  - [Demo](#demo)
  - [Acknowledgments](#acknowledgments)
  - [Development](#development)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

## Description

Angular 2 validation directive for setting and checking `<input type="file" />` value to be required.

Works both with one & multiple files mode.

## Installation
`npm install ng2-file-required --save`

`npm i ng2-file-required -S` (shortcut)

## Usage

**Attention**

For the obsolete and limited `[ng2FileRequired]` usage see [latest git v0.0.0-beta.* tag](https://github.com/pkantsedalov/ng2-file-required/tree/v0.0.0-beta.6)

For current stable version usage follow the next steps:

1. import the module to your one:

```typescript

    import { Ng2FileRequiredModule } from 'ng2-file-required';

    @NgModule({
      ...
      imports: [
        ...
        Ng2FileRequiredModule
      ]
    })
    ...

```

2. then use the directive:

For dynamic attributes explanation see [this stackoverflow example](https://stackoverflow.com/a/36745752/2385788).

```html
    <!-- 
        1. Make it required by default.
        2. The error message is a default one: 'File is required' 
    -->
    <input type="file" [(ngModel)]="myFile" required="required" />
    
    <!-- 
        1. Make it required dynamically.
        2. The error message is a default one: 'File is reqiured'
    -->
    <input type="file" [(ngModel)]="myFile" [attr.required]="{{condition}}" />
    
    <!-- 
        1. Make it required by default.
        2. The error message is customized to 'There should be a file' 
    -->
    <input 
      type="file" 
      [(ngModel)]="myFile"
      required="required"
      [requiredErrorMsg]="'There should be a file'" 
    />

    <!--
        1. Make it required by default.
        2. The error message is customized dynamically
    -->
    <input
      type="file"
      required="required"
      [requiredErrorMsg]="customErrorMessage"
    />
```

## Demo
See it [here](https://pkantsedalov.github.io/ng2-file-required).

## Acknowledgments
I express my gratitude to the [valor-software](https://github.com/valor-software) team.
This project structure is based on their [ng2-file-upload](https://github.com/valor-software/ng2-file-upload) solution, their [tslint configuration](https://github.com/valor-software/tslint-config-valorsoft) and [npm submodules manager](https://www.npmjs.com/package/ngm-cli). 

## Development
1. Clone/fork it
 
2. In `./src` directory you can find the directive sources & unit tests, in the `./demo` one - the files for Github Pages demo.

3. Use next npm scripts for development (they use [angular-cli](https://github.com/angular/angular-cli) and [ngm-cli](https://www.npmjs.com/package/ngm-cli)):
 
    3.1. `npm start` serves with `ng serve` command;
    
    3.2. `npm build` - created `./dist` directory in the end;
    
    3.3 `npm test` - runs unit tests with `ng test` using Karma and Angular 2 testing tools.

    3.4 `npm run e2e` - runs e2e tests using Protractor and Selenium  Webdriver.

---
_Source: https://npm.io/package/ng2-file-required · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
