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

angular-number-input

Package Overview
Dependencies
Maintainers
1
Versions
62
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

angular-number-input

AngularJS number input directive.

  • 2.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3
decreased by-72.73%
Maintainers
1
Weekly downloads
 
Created
Source

angular-number-input

NPM Version CI Coverage Status Known Vulnerabilities Inline docs License

AngularJS number input directive

Overview

The number-input is an angular directive which provides number validation, parsing and formatting capabilities on any HTML element.

Demo

Live Demo

Usage

In order to use the number-input directive you first must add the relevant dependencies:

<script type="text/javascript" src="angular.js"></script>
<script type="text/javascript" src="angular-number-input.js"></script>

Next you must define it as a dependency in your main angular module as follows:

angular.module('exampleApp', [
    'number-input'
]);

Now you can use the directive in your HTML templates, for example:

<input type="text" class="number-input"
  ng-model="value"
  min="-100"
  max="100"
  step="0.5"
  validation="myNumberValidation"
  formatter="myNumberFormatter"
  parser="myNumberParser">

In case you have common parsing/formatting/validations/min/max/step you wish to use in many places in your application, you can create a service to implement those and provide it to the directive as follows:

<input type="text" class="number-input"
  ng-model="value"
  service="myMoneyService">

And an example service:

angular.module('moneyModule', []).service('myMoneyService', function () {
    return {
        create: function () {
            return {
                config: null, //will be populated by the directive with the config which holds the min/max/step/... values
                min: 10,
                max: 100,
                step: 5,
                format: function (value) {
                    if (value) {
                        value = '$' + value;
                    }

                    return value;
                },
                parse: function (value) {
                    if (value) {
                        if (value.charAt(0) === '$') {
                            value = value.substring(1);
                        }
                    }

                    value = Number(value);

                    return value;
                },
                validate: function (modelValue, viewValue) {
                    return true;
                },
                link: function (scope, element, attrs, ngModelCtrl) {
                    //do some custom stuff on the directive instance like adding DOM event handling
                    element.on('keydown', function ($event) {
                        switch ($event.keyCode) {
                        case $.ui.keyCode.ENTER:
                            element.blur();
                            break;
                        }
                    });
                }
            };
        }
    }
});

In case both service and HTML attributes provide a definition for same attributes (for example min, max, parser and so on...), the HTML attribute value will override the service provided value.
If the HTML provided value changes to undefined/null/invalid value, the service value will be used instead.

Installation

Run npm install in your project as follows:

npm install --save angular-number-input

Or if you are using bower, you can install it as follows:

bower install angular-number-input --save

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

DateVersionDescription
2020-05-11v2.0.0Migrate to github actions, upgrade minimal node version and remove bower
2019-02-08v1.1.7Maintenance
2018-02-12v1.1.2Add support for step validations using big.js for more accurate calculations
2018-02-01v1.0.38Link function of the provided service will only be called once to prevent memory leaks
2016-07-11v0.0.27Service can now provide min/max/step values and template values override service values
2016-06-14v0.0.22Published via NPM (in addition to bower)
2016-05-17v0.0.14Directive element now listens to new number-input$update-model event
2016-05-15v0.0.11Redesign of service integration
2016-05-09v0.0.5'service' is now string value and not binded to scope
2016-05-09v0.0.3Adding common service support
2016-05-08v0.0.3Initial release

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

Keywords

FAQs

Package last updated on 11 May 2020

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