在输入控件执行updateValueAndValidity操作后,需要手动更新ngx-mask,以便它能够 correctly bind and validate the input。
代码示例:
import { Component, ViewChild } from '@angular/core'; import { MaskDirective } from 'ngx-mask';
@Component({ selector: 'app-my-component', template: `
` }) export class MyComponent {
myMask = '000-000-0000';
myModel = '';
@ViewChild('myInput') myInput: MaskDirective;
doSomething() {
// update input
this.myInput.update();
}
}