7
I have a Component where I need the input to have the mask for Cpf or cnpj according to the data entry. I am using ng-Mask, but my validation for the mask is only working for the first validation. Below is the code. module ts.
import { NgxMaskModule } from 'ngx-mask';
@NgModule({
declarations: [ .... ],
imports: [
//outros imports
NgxMaskModule.forRoot(),
],
In my Component.ts I am thus using the method.
@Component({
selector: 'app-dados-bancarios-professor',
templateUrl: './dados-bancarios.component.html',
styleUrls: ['./dados-bancarios.component.scss']
})
//regras de negócio do component
mask:string;
cpfcnpjmask() {
const value = this.dadosBancariosForm.get('cpf_cnpj').value;
console.log(value, value.length,this.dadosBancariosForm)
if(value.length <= 14) {
this.mask = '00.000.000/0000-00'
}
else {
this.mask = '00.000.0000-00'
}
}
And why I use the mask as follows in my Component.html
<label class="control-label">CPF/CNPJ<span class="text-danger">*</span></label>
<input type="text" class="form-control form-control-sm" formControlName="cpf_cnpj" [mask]="mask" (keyup)="cpfcnpjmask($event)">
It turns out that he makes the first bind, but does not get to execute the second mask according to what is inserted by the user. Would anyone know how to resolve this impasse?
Try to create a stackblitz of the problem, so I saw the length will never be greater than 14, it should not be the contrary?
– Eduardo Vargas
I discovered that the Ionic brmasker lib has the masks and rotates normally at angle 8
– Betini O. Heleno