ngx-st-qty-input 18.0.0 → 18.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +558 -13
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,24 +1,569 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Quantity Input Component - Complete Documentation
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
## Table of Contents
|
|
4
|
+
- [Overview](#overview)
|
|
5
|
+
- [Installation](#installation)
|
|
6
|
+
- [Basic Usage](#basic-usage)
|
|
7
|
+
- [Inputs](#inputs)
|
|
8
|
+
- [Outputs](#outputs)
|
|
9
|
+
- [Usage Examples](#usage-examples)
|
|
10
|
+
- [Best Practices](#best-practices)
|
|
4
11
|
|
|
5
|
-
|
|
12
|
+
---
|
|
6
13
|
|
|
7
|
-
|
|
8
|
-
> Note: Don't forget to add `--project ngx-st-qty-input` or else it will be added to the default project in your `angular.json` file.
|
|
14
|
+
## Overview
|
|
9
15
|
|
|
10
|
-
|
|
16
|
+
The `ngx-st-qty-input` component is a quantity selector with increment/decrement buttons. Features include:
|
|
17
|
+
- Plus/minus buttons for incrementing/decrementing values
|
|
18
|
+
- Direct numeric input
|
|
19
|
+
- Negative value support (optional)
|
|
20
|
+
- Two-way data binding with model
|
|
21
|
+
- Disabled state support
|
|
22
|
+
- Error state display
|
|
23
|
+
- Change event emission
|
|
11
24
|
|
|
12
|
-
|
|
25
|
+
---
|
|
13
26
|
|
|
14
|
-
##
|
|
27
|
+
## Installation
|
|
15
28
|
|
|
16
|
-
|
|
29
|
+
```bash
|
|
30
|
+
npm install ngx-st-qty-input
|
|
31
|
+
```
|
|
17
32
|
|
|
18
|
-
|
|
33
|
+
Import the module:
|
|
19
34
|
|
|
20
|
-
|
|
35
|
+
```typescript
|
|
36
|
+
import { NgxStQtyInputModule } from 'ngx-st-qty-input';
|
|
21
37
|
|
|
22
|
-
|
|
38
|
+
@NgModule({
|
|
39
|
+
imports: [NgxStQtyInputModule]
|
|
40
|
+
})
|
|
41
|
+
export class AppModule { }
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Basic Usage
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<ngx-st-qty-input
|
|
50
|
+
[(qtyModel)]="quantity">
|
|
51
|
+
</ngx-st-qty-input>
|
|
52
|
+
|
|
53
|
+
<p>Quantity: {{ quantity }}</p>
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
---
|
|
57
|
+
|
|
58
|
+
## Inputs
|
|
59
|
+
|
|
60
|
+
### `qtyModel` (model signal)
|
|
61
|
+
- **Type:** `number`
|
|
62
|
+
- **Required:** Yes
|
|
63
|
+
- **Description:** The quantity value. Uses Angular's model signal for two-way binding.
|
|
64
|
+
- **Example:**
|
|
65
|
+
```html
|
|
66
|
+
[(qtyModel)]="quantity"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### `allowNegative`
|
|
70
|
+
- **Type:** `boolean`
|
|
71
|
+
- **Default:** `false`
|
|
72
|
+
- **Description:** Allows negative values. When false, values below 0 are automatically reset to 0.
|
|
73
|
+
- **Example:**
|
|
74
|
+
```html
|
|
75
|
+
[allowNegative]="true"
|
|
76
|
+
[allowNegative]="false"
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### `disabled`
|
|
80
|
+
- **Type:** `boolean`
|
|
81
|
+
- **Default:** `false`
|
|
82
|
+
- **Description:** Disables the entire component (input and buttons).
|
|
83
|
+
- **Example:**
|
|
84
|
+
```html
|
|
85
|
+
[disabled]="isProcessing"
|
|
86
|
+
[disabled]="true"
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### `showError`
|
|
90
|
+
- **Type:** `boolean`
|
|
91
|
+
- **Default:** `false`
|
|
92
|
+
- **Description:** Shows an error state styling on the input.
|
|
93
|
+
- **Example:**
|
|
94
|
+
```html
|
|
95
|
+
[showError]="quantity < minRequired"
|
|
96
|
+
[showError]="hasValidationError"
|
|
97
|
+
```
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Outputs
|
|
102
|
+
|
|
103
|
+
### `newValueEmitter`
|
|
104
|
+
- **Type:** `number`
|
|
105
|
+
- **Description:** Emitted whenever the quantity value changes (via buttons or direct input).
|
|
106
|
+
- **Example:**
|
|
107
|
+
```typescript
|
|
108
|
+
(newValueEmitter)="onQuantityChange($event)"
|
|
109
|
+
|
|
110
|
+
onQuantityChange(newValue: number): void {
|
|
111
|
+
console.log('New quantity:', newValue);
|
|
112
|
+
this.updateCart(newValue);
|
|
113
|
+
}
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
---
|
|
117
|
+
|
|
118
|
+
## Usage Examples
|
|
119
|
+
|
|
120
|
+
### Example 1: Basic Shopping Cart Quantity
|
|
121
|
+
|
|
122
|
+
```typescript
|
|
123
|
+
// Component
|
|
124
|
+
@Component({
|
|
125
|
+
selector: 'app-cart-item',
|
|
126
|
+
template: `
|
|
127
|
+
<div class="cart-item">
|
|
128
|
+
<img [src]="product.image" [alt]="product.name">
|
|
129
|
+
<h3>{{ product.name }}</h3>
|
|
130
|
+
<p>Price: ${{ product.price }}</p>
|
|
131
|
+
|
|
132
|
+
<ngx-st-qty-input
|
|
133
|
+
[(qtyModel)]="quantity"
|
|
134
|
+
(newValueEmitter)="updateCartItem($event)">
|
|
135
|
+
</ngx-st-qty-input>
|
|
136
|
+
|
|
137
|
+
<p>Total: ${{ total }}</p>
|
|
138
|
+
</div>
|
|
139
|
+
`
|
|
140
|
+
})
|
|
141
|
+
export class CartItemComponent {
|
|
142
|
+
product = {
|
|
143
|
+
id: 1,
|
|
144
|
+
name: 'Product Name',
|
|
145
|
+
price: 19.99,
|
|
146
|
+
image: 'product.jpg'
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
quantity = 1;
|
|
150
|
+
|
|
151
|
+
get total(): number {
|
|
152
|
+
return this.product.price * this.quantity;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
updateCartItem(newQuantity: number): void {
|
|
156
|
+
console.log('Updating cart with quantity:', newQuantity);
|
|
157
|
+
// API call to update cart
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
### Example 2: With Negative Values
|
|
163
|
+
|
|
164
|
+
```typescript
|
|
165
|
+
// Component
|
|
166
|
+
@Component({
|
|
167
|
+
selector: 'app-adjustment',
|
|
168
|
+
template: `
|
|
169
|
+
<h3>Stock Adjustment</h3>
|
|
170
|
+
<p>Current Stock: {{ currentStock }}</p>
|
|
171
|
+
|
|
172
|
+
<label>Adjustment:</label>
|
|
173
|
+
<ngx-st-qty-input
|
|
174
|
+
[(qtyModel)]="adjustment"
|
|
175
|
+
[allowNegative]="true"
|
|
176
|
+
(newValueEmitter)="calculateNewStock($event)">
|
|
177
|
+
</ngx-st-qty-input>
|
|
178
|
+
|
|
179
|
+
<p>New Stock: {{ newStock }}</p>
|
|
180
|
+
<button (click)="applyAdjustment()">Apply</button>
|
|
181
|
+
`
|
|
182
|
+
})
|
|
183
|
+
export class StockAdjustmentComponent {
|
|
184
|
+
currentStock = 100;
|
|
185
|
+
adjustment = 0;
|
|
186
|
+
newStock = 100;
|
|
187
|
+
|
|
188
|
+
calculateNewStock(adjustment: number): void {
|
|
189
|
+
this.newStock = this.currentStock + adjustment;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
applyAdjustment(): void {
|
|
193
|
+
this.currentStock = this.newStock;
|
|
194
|
+
this.adjustment = 0;
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### Example 3: Disabled State
|
|
200
|
+
|
|
201
|
+
```typescript
|
|
202
|
+
// Component
|
|
203
|
+
@Component({
|
|
204
|
+
selector: 'app-disabled-qty',
|
|
205
|
+
template: `
|
|
206
|
+
<ngx-st-qty-input
|
|
207
|
+
[(qtyModel)]="quantity"
|
|
208
|
+
[disabled]="outOfStock">
|
|
209
|
+
</ngx-st-qty-input>
|
|
210
|
+
|
|
211
|
+
<p *ngIf="outOfStock" class="error">Out of Stock</p>
|
|
212
|
+
<button (click)="toggleStock()">Toggle Stock</button>
|
|
213
|
+
`
|
|
214
|
+
})
|
|
215
|
+
export class DisabledQtyComponent {
|
|
216
|
+
quantity = 1;
|
|
217
|
+
outOfStock = false;
|
|
218
|
+
|
|
219
|
+
toggleStock(): void {
|
|
220
|
+
this.outOfStock = !this.outOfStock;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
```
|
|
224
|
+
|
|
225
|
+
### Example 4: With Validation and Error Display
|
|
226
|
+
|
|
227
|
+
```typescript
|
|
228
|
+
// Component
|
|
229
|
+
@Component({
|
|
230
|
+
selector: 'app-validated-qty',
|
|
231
|
+
template: `
|
|
232
|
+
<div class="qty-input-wrapper">
|
|
233
|
+
<label>Quantity (Min: {{ minQty }}, Max: {{ maxQty }}):</label>
|
|
234
|
+
<ngx-st-qty-input
|
|
235
|
+
[(qtyModel)]="quantity"
|
|
236
|
+
[showError]="hasError"
|
|
237
|
+
(newValueEmitter)="validate($event)">
|
|
238
|
+
</ngx-st-qty-input>
|
|
239
|
+
|
|
240
|
+
<p *ngIf="hasError" class="error-message">
|
|
241
|
+
{{ errorMessage }}
|
|
242
|
+
</p>
|
|
243
|
+
</div>
|
|
244
|
+
`
|
|
245
|
+
})
|
|
246
|
+
export class ValidatedQtyComponent {
|
|
247
|
+
quantity = 1;
|
|
248
|
+
minQty = 1;
|
|
249
|
+
maxQty = 10;
|
|
250
|
+
hasError = false;
|
|
251
|
+
errorMessage = '';
|
|
252
|
+
|
|
253
|
+
validate(value: number): void {
|
|
254
|
+
if (value < this.minQty) {
|
|
255
|
+
this.hasError = true;
|
|
256
|
+
this.errorMessage = `Minimum quantity is ${this.minQty}`;
|
|
257
|
+
} else if (value > this.maxQty) {
|
|
258
|
+
this.hasError = true;
|
|
259
|
+
this.errorMessage = `Maximum quantity is ${this.maxQty}`;
|
|
260
|
+
} else {
|
|
261
|
+
this.hasError = false;
|
|
262
|
+
this.errorMessage = '';
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
### Example 5: Multiple Quantity Inputs
|
|
269
|
+
|
|
270
|
+
```typescript
|
|
271
|
+
// Component
|
|
272
|
+
@Component({
|
|
273
|
+
selector: 'app-order-form',
|
|
274
|
+
template: `
|
|
275
|
+
<h3>Order Products</h3>
|
|
276
|
+
<div *ngFor="let item of orderItems" class="order-item">
|
|
277
|
+
<span>{{ item.name }}</span>
|
|
278
|
+
<ngx-st-qty-input
|
|
279
|
+
[(qtyModel)]="item.quantity"
|
|
280
|
+
(newValueEmitter)="updateItemTotal(item)">
|
|
281
|
+
</ngx-st-qty-input>
|
|
282
|
+
<span>{{ item.price | currency }} each</span>
|
|
283
|
+
<span>Total: {{ item.total | currency }}</span>
|
|
284
|
+
</div>
|
|
285
|
+
|
|
286
|
+
<div class="order-summary">
|
|
287
|
+
<h4>Order Total: {{ orderTotal | currency }}</h4>
|
|
288
|
+
</div>
|
|
289
|
+
`
|
|
290
|
+
})
|
|
291
|
+
export class OrderFormComponent {
|
|
292
|
+
orderItems = [
|
|
293
|
+
{ id: 1, name: 'Item 1', price: 10, quantity: 1, total: 10 },
|
|
294
|
+
{ id: 2, name: 'Item 2', price: 15, quantity: 2, total: 30 },
|
|
295
|
+
{ id: 3, name: 'Item 3', price: 20, quantity: 1, total: 20 }
|
|
296
|
+
];
|
|
297
|
+
|
|
298
|
+
updateItemTotal(item: any): void {
|
|
299
|
+
item.total = item.price * item.quantity;
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
get orderTotal(): number {
|
|
303
|
+
return this.orderItems.reduce((sum, item) => sum + item.total, 0);
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
```
|
|
307
|
+
|
|
308
|
+
### Example 6: With Min/Max Enforcement
|
|
309
|
+
|
|
310
|
+
```typescript
|
|
311
|
+
// Component
|
|
312
|
+
@Component({
|
|
313
|
+
selector: 'app-constrained-qty',
|
|
314
|
+
template: `
|
|
315
|
+
<label>Select Quantity (1-100):</label>
|
|
316
|
+
<ngx-st-qty-input
|
|
317
|
+
[(qtyModel)]="quantity"
|
|
318
|
+
[showError]="isOutOfRange"
|
|
319
|
+
(newValueEmitter)="enforceRange($event)">
|
|
320
|
+
</ngx-st-qty-input>
|
|
321
|
+
|
|
322
|
+
<p *ngIf="isOutOfRange" class="warning">
|
|
323
|
+
Quantity must be between 1 and 100
|
|
324
|
+
</p>
|
|
325
|
+
`
|
|
326
|
+
})
|
|
327
|
+
export class ConstrainedQtyComponent {
|
|
328
|
+
quantity = 1;
|
|
329
|
+
minValue = 1;
|
|
330
|
+
maxValue = 100;
|
|
331
|
+
isOutOfRange = false;
|
|
332
|
+
|
|
333
|
+
enforceRange(value: number): void {
|
|
334
|
+
this.isOutOfRange = false;
|
|
335
|
+
|
|
336
|
+
if (value < this.minValue) {
|
|
337
|
+
this.quantity = this.minValue;
|
|
338
|
+
this.isOutOfRange = true;
|
|
339
|
+
} else if (value > this.maxValue) {
|
|
340
|
+
this.quantity = this.maxValue;
|
|
341
|
+
this.isOutOfRange = true;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
```
|
|
346
|
+
|
|
347
|
+
### Example 7: Real-time Price Calculator
|
|
348
|
+
|
|
349
|
+
```typescript
|
|
350
|
+
// Component
|
|
351
|
+
@Component({
|
|
352
|
+
selector: 'app-price-calculator',
|
|
353
|
+
template: `
|
|
354
|
+
<div class="calculator">
|
|
355
|
+
<h3>{{ product.name }}</h3>
|
|
356
|
+
<img [src]="product.image" [alt]="product.name">
|
|
357
|
+
|
|
358
|
+
<div class="price-info">
|
|
359
|
+
<p>Unit Price: {{ product.price | currency }}</p>
|
|
360
|
+
|
|
361
|
+
<div class="qty-selector">
|
|
362
|
+
<label>Quantity:</label>
|
|
363
|
+
<ngx-st-qty-input
|
|
364
|
+
[(qtyModel)]="quantity"
|
|
365
|
+
[disabled]="!product.inStock"
|
|
366
|
+
(newValueEmitter)="calculatePrice($event)">
|
|
367
|
+
</ngx-st-qty-input>
|
|
368
|
+
</div>
|
|
369
|
+
|
|
370
|
+
<div class="discount" *ngIf="discount > 0">
|
|
371
|
+
<p>Discount: -{{ discount | currency }}</p>
|
|
372
|
+
</div>
|
|
373
|
+
|
|
374
|
+
<div class="total">
|
|
375
|
+
<h2>Total: {{ totalPrice | currency }}</h2>
|
|
376
|
+
</div>
|
|
377
|
+
|
|
378
|
+
<button
|
|
379
|
+
[disabled]="!product.inStock"
|
|
380
|
+
(click)="addToCart()">
|
|
381
|
+
Add to Cart
|
|
382
|
+
</button>
|
|
383
|
+
</div>
|
|
384
|
+
</div>
|
|
385
|
+
`
|
|
386
|
+
})
|
|
387
|
+
export class PriceCalculatorComponent {
|
|
388
|
+
product = {
|
|
389
|
+
id: 1,
|
|
390
|
+
name: 'Premium Widget',
|
|
391
|
+
price: 29.99,
|
|
392
|
+
image: 'widget.jpg',
|
|
393
|
+
inStock: true
|
|
394
|
+
};
|
|
395
|
+
|
|
396
|
+
quantity = 1;
|
|
397
|
+
totalPrice = 29.99;
|
|
398
|
+
discount = 0;
|
|
399
|
+
|
|
400
|
+
calculatePrice(qty: number): void {
|
|
401
|
+
const subtotal = this.product.price * qty;
|
|
402
|
+
|
|
403
|
+
// Apply bulk discounts
|
|
404
|
+
if (qty >= 10) {
|
|
405
|
+
this.discount = subtotal * 0.1; // 10% off
|
|
406
|
+
} else if (qty >= 5) {
|
|
407
|
+
this.discount = subtotal * 0.05; // 5% off
|
|
408
|
+
} else {
|
|
409
|
+
this.discount = 0;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
this.totalPrice = subtotal - this.discount;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
addToCart(): void {
|
|
416
|
+
console.log(`Adding ${this.quantity} items to cart`);
|
|
417
|
+
// Add to cart logic
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
### Example 8: With Stock Availability
|
|
423
|
+
|
|
424
|
+
```typescript
|
|
425
|
+
// Component
|
|
426
|
+
@Component({
|
|
427
|
+
selector: 'app-stock-aware-qty',
|
|
428
|
+
template: `
|
|
429
|
+
<div class="product">
|
|
430
|
+
<h3>{{ product.name }}</h3>
|
|
431
|
+
<p>Available Stock: {{ product.stock }}</p>
|
|
432
|
+
|
|
433
|
+
<ngx-st-qty-input
|
|
434
|
+
[(qtyModel)]="quantity"
|
|
435
|
+
[showError]="exceedsStock"
|
|
436
|
+
[disabled]="product.stock === 0"
|
|
437
|
+
(newValueEmitter)="checkStock($event)">
|
|
438
|
+
</ngx-st-qty-input>
|
|
439
|
+
|
|
440
|
+
<p *ngIf="exceedsStock" class="error">
|
|
441
|
+
Only {{ product.stock }} items available
|
|
442
|
+
</p>
|
|
443
|
+
|
|
444
|
+
<p *ngIf="product.stock === 0" class="out-of-stock">
|
|
445
|
+
Out of Stock
|
|
446
|
+
</p>
|
|
447
|
+
|
|
448
|
+
<button
|
|
449
|
+
[disabled]="exceedsStock || product.stock === 0"
|
|
450
|
+
(click)="purchase()">
|
|
451
|
+
Purchase
|
|
452
|
+
</button>
|
|
453
|
+
</div>
|
|
454
|
+
`
|
|
455
|
+
})
|
|
456
|
+
export class StockAwareQtyComponent {
|
|
457
|
+
product = {
|
|
458
|
+
name: 'Limited Edition Item',
|
|
459
|
+
stock: 5
|
|
460
|
+
};
|
|
461
|
+
|
|
462
|
+
quantity = 1;
|
|
463
|
+
exceedsStock = false;
|
|
464
|
+
|
|
465
|
+
checkStock(qty: number): void {
|
|
466
|
+
if (qty > this.product.stock) {
|
|
467
|
+
this.exceedsStock = true;
|
|
468
|
+
// Optionally auto-correct
|
|
469
|
+
this.quantity = this.product.stock;
|
|
470
|
+
} else {
|
|
471
|
+
this.exceedsStock = false;
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
purchase(): void {
|
|
476
|
+
this.product.stock -= this.quantity;
|
|
477
|
+
console.log(`Purchased ${this.quantity} items`);
|
|
478
|
+
this.quantity = 1;
|
|
479
|
+
}
|
|
480
|
+
}
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
---
|
|
484
|
+
|
|
485
|
+
## Best Practices
|
|
486
|
+
|
|
487
|
+
1. **Set appropriate initial values**:
|
|
488
|
+
```typescript
|
|
489
|
+
quantity = 1; // Don't start with 0 for shopping carts
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
2. **Use validation** to enforce business rules:
|
|
493
|
+
```typescript
|
|
494
|
+
onQuantityChange(qty: number): void {
|
|
495
|
+
if (qty > maxStock) {
|
|
496
|
+
this.quantity = maxStock;
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
```
|
|
500
|
+
|
|
501
|
+
3. **Disable when not applicable**:
|
|
502
|
+
```html
|
|
503
|
+
[disabled]="outOfStock || isProcessing"
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
4. **Show errors for invalid values**:
|
|
507
|
+
```html
|
|
508
|
+
[showError]="quantity < minRequired || quantity > maxAllowed"
|
|
509
|
+
```
|
|
510
|
+
|
|
511
|
+
5. **Use `allowNegative` only when needed**:
|
|
512
|
+
```html
|
|
513
|
+
<!-- For adjustments -->
|
|
514
|
+
[allowNegative]="true"
|
|
515
|
+
|
|
516
|
+
<!-- For quantities (default) -->
|
|
517
|
+
[allowNegative]="false"
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
6. **Provide feedback** on changes:
|
|
521
|
+
```typescript
|
|
522
|
+
onQuantityChange(qty: number): void {
|
|
523
|
+
this.updateTotal();
|
|
524
|
+
this.checkAvailability();
|
|
525
|
+
this.calculateShipping();
|
|
526
|
+
}
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
7. **Consider debouncing** for API calls:
|
|
530
|
+
```typescript
|
|
531
|
+
onQuantityChange = debounce((qty: number) => {
|
|
532
|
+
this.updateCartOnServer(qty);
|
|
533
|
+
}, 500);
|
|
534
|
+
```
|
|
535
|
+
|
|
536
|
+
---
|
|
537
|
+
|
|
538
|
+
## Component Behavior
|
|
539
|
+
|
|
540
|
+
### Increment Button (+)
|
|
541
|
+
- Increases value by 1
|
|
542
|
+
- Emits `newValueEmitter` event
|
|
543
|
+
- Disabled when component is disabled
|
|
544
|
+
|
|
545
|
+
### Decrement Button (-)
|
|
546
|
+
- Decreases value by 1
|
|
547
|
+
- If `allowNegative` is false and value would go below 0, sets to 0
|
|
548
|
+
- Emits `newValueEmitter` event
|
|
549
|
+
- Disabled when component is disabled
|
|
550
|
+
|
|
551
|
+
### Direct Input
|
|
552
|
+
- Allows manual entry of numeric values
|
|
553
|
+
- Validates and corrects negative values if `allowNegative` is false
|
|
554
|
+
- Emits `newValueEmitter` event on blur or enter
|
|
555
|
+
|
|
556
|
+
---
|
|
557
|
+
|
|
558
|
+
## Common Use Cases
|
|
559
|
+
|
|
560
|
+
1. **Shopping Cart**: Product quantity selection
|
|
561
|
+
2. **Inventory Management**: Stock adjustments (with negative values)
|
|
562
|
+
3. **Order Forms**: Quantity selection for multiple items
|
|
563
|
+
4. **Configurators**: Selecting quantities of customizable items
|
|
564
|
+
5. **Bulk Operations**: Specifying number of items to process
|
|
565
|
+
|
|
566
|
+
---
|
|
567
|
+
|
|
568
|
+
This documentation covers all inputs, outputs, and usage patterns for the Quantity Input component.
|
|
23
569
|
|
|
24
|
-
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI Overview and Command Reference](https://angular.io/cli) page.
|