【发布时间】:2018-08-27 13:31:30
【问题描述】:
我们正在使用来自 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">`
【问题讨论】:
标签: angular