imaskjs icon indicating copy to clipboard operation
imaskjs copied to clipboard

Angular - Dynamic mask dont update ngModel

Open penihel opened this issue 3 years ago • 0 comments

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,:

image

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.

image

I need to decide to apply or not apply a mask.

What i did wrong?

penihel avatar Nov 10 '21 14:11 penihel