A very versatile Angular Digit Input Directive with customizable digit grouping, decimal separators, etc.
In the terminal, type
npm i ng-indigit
Now import the module in your angular module, e.g. app.module.ts
:
import { NgIndigitModule } from 'ng-indigit';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgIndigitModule
],
bootstrap: [AppComponent]
})
export class AppModule {}
In your template file, add the ng-indigit
attribute to an HTML text input, e.g.:
<input type="text" ng-indigit formControlName="value"/>
You can pass the following attributes values of supported types for further customizations:
Attribute | Supported Type | Default | Description |
---|---|---|---|
digitGroups (since v0.3.11) |
|
|
Set digit grouping parameters for integer and decimal[*] parts of the number at once.
You can set the groups' delimiter character and/or the group size for the decimal/integer part together/distinctively. |
integerDigitGroups
|
|
|
Set digit grouping parameters for integer and decimal[*] parts of a number.
You can set the groups' delimiter character and/or the group size. |
decimal [*]
|
|
|
Set parameters for decimal numbers[*].
You can set the decimal separator (float point character), and/or minimum / maximum number of decimal digits. |
allowNegative
|
boolean [**]
|
false
|
Toggle support for negative numbers. |
You may also pass an object of TPrettyFloatOption type as
the NG_INDIGIT_PRETTY_FLOAT_CONFIG
provider to the module that imports NgIndigitModule;
e.g.:
import { NgIndigitModule, NG_INDIGIT_PRETTY_FLOAT_CONFIG } from 'ng-indigit';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
NgIndigitModule
],
providers: [
{
provide: NG_INDIGIT_PRETTY_FLOAT_CONFIG,
useValue: {
digitGroups: { delimiter: ',', groupSize: 3, hasDigitGroups: true },
decimal: { maxDigitCount: 4, minDigitCount: 0, isDecimalAllowed: true }
}
},
],
bootstrap: [AppComponent]
})
export class AppModule {}
- Clone the GitHub repo:
git clone git@github.com:vahidm90/ng-indigit.git
- Install the dependencies/package contents:
cd ng-indigit
npm install
- Build the directive:
ng build
- Run the demo app
ng serve
- Navigate to http://localhost:4200 on your browser to see a running demo.
Any pull request is welcome!
Here's a list of ideas to begin with:
- Automated tests, versioning, changelogs; or better said a perfect CI/CD pipelining
- Full support for decimal numbers
- Full support for negative numbers
- Compatibility tests & implementation for older/newer versions of Angular
- Documentation
Many thanks to Javad Rasouli for the idea to develop this in the first place, and to Hossein Salmanian for valuable tips and feedbacks.
NgIndigit is free and licensed under the MIT License.
* Support for decimal numbers is experimental.
** For boolean
properties, adding only the attribute name or passing any truthy value is identical with
passing true
as the property's value.