imaskjs
imaskjs copied to clipboard
Angular - Dynamic mask dont update ngModel
I have this component in angular (version "angular-imask": "6.2.2") and Angular 12.2
<input [type]="text"
[(ngModel)]="model.documento"
[imask]="getTipoDocumentoMask(model.idTipoDocumento)"
/>
<span>{{model.documento}}</span>
the typescript
getTipoDocumentoMask(idTipoDocumento: string) {
if (!idTipoDocumento)
return null;
switch (idTipoDocumento) {
case TiposDocumentos.CPF:
return { mask: '000.000.000-00' };
default:
return null;
}
The de component starts. The model is null, so whe ajax callback return, the model is populated, and the input show de value,:
BUT, my model property (ngModel) still empty. Look that span not not show any value
Only after i type something in the input, so value that the model property (ngModel) is updated.
I need to decide to apply or not apply a mask.
What i did wrong?