ngx-numeric-counter
Version:
Angular component for numeric input with increment and decrement buttons.
165 lines (113 loc) • 4.25 kB
Markdown
> Angular component for numeric input with increment and decrement buttons.
[](https://www.npmjs.com/package/ngx-numeric-counter)
[](https://www.npmjs.com/package/ngx-numeric-counter)
---
✅ Increment and decrement buttons
✅ Works with [(ngModel)] and Reactive Forms
✅ Configurable min, max, and step
✅ Works in standalone components and NgModules
✅ Lightweight and no dependencies
---
Install the package via npm:
```bash
npm install --save ngx-numeric-counter
```
or with yarn:
```bash
yarn add ngx-numeric-counter
```
If you’re using Angular standalone components:
```typescript
import { Component } from '@angular/core';
import { NgxNumericCounterComponent } from 'ngx-numeric-counter';
@Component({
standalone: true,
imports: [NgxNumericCounterComponent],
template: `
<ngx-numeric-counter
[(ngModel)]="quantity"
[]="1"
[]="10"
[]="1"
></ngx-numeric-counter>
<p>Quantity: {{ quantity }}</p>
`
})
export class DemoComponent {
quantity = 3;
}
```
Or import the module in your NgModule:
```typescript
import { NgxNumericCounterModule } from 'ngx-numeric-counter';
@NgModule({
imports: [NgxNumericCounterModule],
})
export class AppModule {}
```
```typescript
import { Component } from '@angular/core';
import { FormBuilder, FormGroup, ReactiveFormsModule } from '@angular/forms';
import { NumericCounterComponent } from 'ngx-numeric-counter';
@Component({
standalone: true,
imports: [ReactiveFormsModule, NumericCounterComponent],
template: `
<form [formGroup]="form">
<ngx-numeric-counter
formControlName="quantity"
[]="1"
[]="10"
></ngx-numeric-counter>
</form>
<p>Value: {{ form.value | json }}</p>
`
})
export class DemoReactiveComponent {
form: FormGroup;
constructor(private fb: FormBuilder) {
this.form = this.fb.group({
quantity: [5]
});
}
}
```
| Property | Type | Default | Description |
|------------------|-----------|----------------------------|-------------------------------------------------|
| `min` | `number` | `Number.NEGATIVE_INFINITY` | Minimum value allowed. |
| `max` | `number` | `Number.POSITIVE_INFINITY` | Maximum value allowed. |
| `step` | `number` | `1` | Increment/decrement step value. |
| `disabled` | `boolean` | `false` | Disables the input and the buttons. |
| `buttonClass` | `string` | `''` | Additional CSS classes for the increment/decrement buttons. |
| `inputClass` | `string` | `''` | Additional CSS classes for the input field. |
| `containerClass` | `string` | `''` | Additional CSS classes for the entire component wrapper. |
Here’s how to style the counter with Tailwind:
```html
<ngx-numeric-counter
[(ngModel)]="qty"
[]="'bg-blue-500 text-white px-3 py-1 rounded hover:bg-blue-600'"
[]="'border border-gray-300 w-16 text-center text-lg rounded'"
[]="'flex gap-2 items-center'"
></ngx-numeric-counter>
```
Angular 17+
Modern browsers
MIT © 2025
---
If you find this library helpful, you can support my work:
[](https://buymeacoffee.com/leonardomatiz)
👉 [Buy Me a Coffee](https://buymeacoffee.com/leonardomatiz)
angular, ngx, numeric counter, number input, counter input, stepper, angular standalone, angular forms, ngmodule, reactive forms