typescript - Angular 5 自定义输入管道在删除字符时失去焦点
问题描述
我有一个自定义管道输入,每插入 4 个字符就添加一个空格。问题是,如果我插入例如“1234 5678”然后我去删除 4,焦点而不是留在那里插入一个新字符,它会移动到最后。
管道
import { Pipe, PipeTransform } from "@angular/core";
@Pipe({
name: 'formatBankAcc'
})
export class FormatBankAccPipe implements PipeTransform {
transform(value: string) {
if (value != null) {
value = value.replace(/[^\dA-Z]/g, '')
.replace(/(.{4})/g, '$1 ')
.trim();
}
return value;
}
}
HTML
<ion-input #editInput type="{{ !servicesPerBillingAccountViewModel.editable ? 'hidden' : 'text' }}" maxlength="29" [ngModel]="billingAccount.bankAccountNumber | formatBankAcc"
(ngModelChange)="billingAccount.bankAccountNumber=$event"
[class.input-border-bottom-grey]="billingAccount.showConfirmCancelIcons"
[class.input-border-validation-error]="billingAccount.showLabelError"
[placeholder]="servicesPerBillingAccountsCmsModel.literalBankPlaceholder"
(keyup)="checkBankAccLength(billingAccount)">
</ion-input>
解决方案
推荐阅读
- python - 填补泰坦尼克数据集中缺失的年龄
- python - 读取没有data_only openpyxl python的单元格的值
- r - 有人可以帮我计算所选列中所有行的平均值和标准差吗
- unit-testing - 单元测试包含 vuetify 的 vue 组件
- android - 从 AutoCompleteTextView 中删除顶部和底部的黑色边框
- ansible - Ansible 角色 - 无法检测过滤器插件
- javascript - 设置用户代理不适用于 puppeteer / tor 配置
- angular - 具有大型数据集的 Mat Multi Select 中的性能问题
- python-3.x - 如果boundingRect接触线,如何计算车辆数
- mysql - 错误:在 MySQL 中将 Varchar 值更新为 Datetime