[Solved] how to auto add two decimal places to the input field in angular 4


So what you basically need is masking your input. angular2-text-mask provides you a directive which you can use on your input elements like this:

<input [textMask]="{mask: amountMask}">

Where amountMask is a property declared your component:

 public amountMask= createNumberMask({
        prefix: '',
        allowDecimal: true,
        decimalLimit: 2
    }); 

To install angular2-text-mask package:

npm i angular2-text-mask --save

createNumberMask is part of the text-mask-addons package, to install:

npm i text-mask-addons --save

Then you need to import like this:

import {createNumberMask} from 'text-mask-addons';

Github page for further info on angular2-text-mask

https://github.com/text-mask/text-mask/tree/master/angular2

Github page for text-mask-addons

https://github.com/text-mask/text-mask/tree/master/addons/

Demo:
https://text-mask.github.io/text-mask/

0

solved how to auto add two decimal places to the input field in angular 4