JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q25358F
  • License ISC

Angular 2 library for handling numbers inside input text fields

Package Exports

  • numerix

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (numerix) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

numerix

numerix is an Angular 2 library (tested on version 8) which offers a bunch of directives for handling numbers inside input text fields. Basically it validates the input according to the directive used and it doesn't allow the user to type invalid characters.

Installing

npm install -s numerix

Usage

The library provides directives for handling natural, integer and floating point numbers. You can use the directives just by importing them into your app.module.ts file like follows:

//app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IntegerDirective, FloatDirective, NaturalDirective } from 'numerix';
import { AppComponent } from './app.component';

@NgModule({
  declarations: [
    AppComponent,
    IntegerDirective,
    NaturalDirective,
    FloatDirective
  ],
  imports: [
    BrowserModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

After the directives have been imported, you can use them with input text fields. The following example show all the directives and all the possible options for each directive.

Example

<table>
  <tbody>
    <tr><td>Natural:    </td><td><input (valid)="valid()" (invalid)="invalid()" natural></td></tr>
    <tr><td>Integer:    </td><td><input (valid)="valid()" (invalid)="invalid()" integer></td></tr>
    <tr><td>Float(,):   </td><td><input (valid)="valid()" (invalid)="invalid()" separator="," float></td></tr>
    <tr><td>Float(.):   </td><td><input (valid)="valid()" (invalid)="invalid()" float></td></tr>
    <tr><td>Float(.2):  </td><td><input (valid)="valid()" (invalid)="invalid()" maxDecimals="2" float></td></tr>
    <tr><td>Float(,1):  </td><td><input (valid)="valid()" (invalid)="invalid()" separator="," maxDecimals="1" float></td></tr>
  </tbody>
</table>

valid and invalid events are fired whenever respectively valid and invalid text (according to the directive used) is typed into the text field.

Authors

  • Maurizio Macrì

License

This project is licensed under the ISC License