【发布时间】:2020-10-07 20:53:11
【问题描述】:
我有一个常规的角度材质表单,它使用 numberMaskOptions 将字段值的输入和显示限制为 3 个小数点。 (见下面的代码)
这很好,但客户现在希望将字段的“显示”限制为仅显示 2 个小数点,但希望允许用户在同一字段中输入最多 3 个小数点。
换句话说,当光标不在该字段中时,它应该显示2个小数点的精度,但是当用户进入该字段进行编辑时,它应该允许3个小数点的精度。
这对材质 matInput 字段是否可行?如果有怎么办?如果不是,我还应该如何处理?
<div *ngIf="isFieldVisible">
<mat-form-field myAppTooltip>
<mat-label>Insect Body Size</mat-label>
<input
autocomplete="off"
appNumberMask
formControlName="InsectBodySizeSmm"
matInput
max="99999"
min="0"
[numberMaskOptions]="threeDecPrecisionDecimalMaskOptions"
/>
<mat-error></mat-error>
</mat-form-field>
</div>
带着我的面具
threeDecPrecisionDecimalMaskOptions = {
align: 'right',
allowNegative: false,
decimalSeparator: '.',
precision: 3,
prefix: '',
suffix: '',
thousandsSeparator: '',
valueMode: 'standard',
};
这允许我在字段表单中输入和查看小数点后 3 位的值。
【问题讨论】:
标签: html angular forms angular-material