angular - ngx-mask 接受负数
问题描述
我们正在使用来自 ngx-mask 的 MaskDirective 和 MaskService,以使用户接受以下格式的输入货币:000000.00。
以下是我的指示。我正在使用输入类型 =“十进制”。现在我有一个场景,其中该指令应该接受一个负数(如果有的话)。
我该如何实施?尝试使用“specialCharacters”,但我无法通过。
非常感谢任何帮助。提前致谢。
`@Directive({
selector: 'input[type=decimal]',
providers: [
{
provide: NG_VALUE_ACCESSOR,
useExisting: forwardRef(() => DecimalDirective),
multi: true,
},
MaskService,
],
})
export class DecimalDirective extends MaskDirective implements OnInit {
@HostBinding('type') public type = 'text';
ngOnInit() {
this.maskExpression = '099999.00';
this.dropSpecialCharacters = false;
}
}`
用法:
`<input type="decimal" name="sampleAmount" formControlName="sampleAmount" class="form-control" placeholder="0.00">`
解决方案
<input mask="V0*.00"
[patterns]="customPatterns"
[dropSpecialCharacters]="false">
customPatterns = {
'V': {pattern: new RegExp('-?')},
'0': {pattern: new RegExp('[0-9]')}
}
推荐阅读
- javascript - 防止快速单击后端按钮
- django - DRF:无法使用视图名称“tickettype-detail”解析超链接关系的 URL
- python - 有没有办法在嵌套的 for 循环中访问生成器中每个元素的属性?
- python - Pandas to_sql 返回 cx_Oracle.DatabaseError: ORA-00942: 表或视图不存在
- sql-server - 如何在 DBeaver 中创建数据库备份并还原?
- powershell - 如何在 Powershell 中从 $pattern 中删除多行文本块
- azure-ad-b2c - 关于文化的问题:RFC5646 和 ContentDefinitions
- python - 合并两个复杂的 JSON 对象
- mysql - MySQL在重复值中选择一个字段
- docker - 如何在生产环境中发布在 docker 容器中运行的网站?