我正在寻找一个用于Ionic4 type=angular的实时货币掩码,它将以反应性的形式实现,也就是说,当您通过添加千分隔符自动键入它的格式时。
我使用了“angular2-text-掩码”:"8.0.1“与”文本掩码-加载项“:"3.5.1”表示成功,但它使用了ngModel和模板表单。任何反应形式或建议的解决方案将不胜感激。
发布于 2019-05-01 20:10:46
好的,所以我找到了一个适用于Ionic 4的解决方案,它使用了几乎所有的实时掩码,包括一个可定制的货币掩码。它也适用于反应性表单和模板表单。如果您使用的是离子4,请安装angualr 2文本掩码https://github.com/text-mask/text-mask/tree/master/angular2并按照以下说明操作:
<label for="lb">Bond/ Rental?</label>
<input formControlName = 'bond' class="form-control" id = "lb"
[textMask]="{mask:numberMask}" type ="tel" />货币掩码的页组件代码是一个变量:
numberMask = createNumberMask({ prefix:'', thousandsSeparatorSymbol: ',', allowDecimal: true, decimalSymbol: '.' });代码中还有标准的表单--我使用了表单生成器。
this.housingForm = formBuilder.group({
bond: ['' , Validators.compose([Validators.required])],
......我希望这能帮到其他人。
发布于 2019-05-24 15:15:44
我也面临着同样的问题,最后我使用了(ionChange)
<ion-input [formControlName]="NAME" (ionChange)="formatCurrency($event)"></ion-input>TS
formatCurrency($event) {
var aux = $event.target.value;
aux = aux.replace(/\./g, "");
aux = aux.replace(/\s/g, "");
aux = aux.replace(/\$/g, "");
aux = aux.replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.');
if (aux.length > 1) aux = aux.replace(/^0+/, ''); /* Replace leading zeros */
$event.target.value = "$" + aux;
}这是一个简单的解决方案,也是我找到的唯一使用ion-input的解决方案。
https://stackoverflow.com/questions/55918344
复制相似问题