1.0.1 • Published 4 years ago
ths-input-currency v1.0.1
ths-input-currency
Installing and Importing
Install the package by command:
npm install ths-input-currency --saveImport the module
import { InputCurrencyModule } from 'ths-input-currency';
@NgModule({
imports: [
...
InputCurrencyModule
],
declarations: [...],
providers: [...]
})
export class AppModule {}Using
<input InputCurrency [(ngModel)]="value" (ngModelChange)="changeValue($event)" />ngModelAn attribute of type number. If is displayed'$ 25.63', the attribute will be'25.63'.
changeValue(value) {
this.value = (value == null ? 0 : value);
}Options
You can set options...
Available options:
align- Text alignment in input. (default:right)allowNegative- Iftruecan input negative values. (default:true)decimal- Separator of decimals (default:'.')precision- Number of decimal places (default:2)prefix- Money prefix (default:'$ ')suffix- Money suffix (default:'')thousands- Separator of thousands (default:',')min- The minimum value (default:undefined)max- The maximum value (default:undefined)
You can also set options globally...
import { InputCurrencyModule } from "ths-input-currency";
export const customCurrencyMaskConfig = {
align: "right",
allowNegative: true,
allowZero: true,
decimal: ",",
precision: 2,
prefix: "R$ ",
suffix: "",
thousands: ".",
min: null,
max: null,
};
@NgModule({
imports: [
...
InputCurrencyModule.forRoot(customCurrencyMaskConfig)
],
declarations: [...],
providers: [...],
bootstrap: [AppComponent]
})
export class AppModule {}