Como aplicar uma máscara de telefone aonde se adapte a um telefone fixo e celular, usando o Angular2-text-mask
?
Li a documentação e vi que da pra fazer com função, porem como estou utilizando formGroup
, não sei como pegar o valor do meu campo...
// Mascaras
cpfMask = [/\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, '-', /\d/, /\d/];
cepMask = [/\d/, /\d/, /\d/, /\d/ , /\d/, '-', /\d/, /\d/, /\d/];
constructor(fb: FormBuilder, public router: Router, private vwServicePagination: VwServicePagination){
//Grupo de formulario - Validações
this.myForm = fb.group({
nome: new FormControl('', [ Validators.required, Validators.minLength(2), this.validaNome ]),
email: new FormControl('', [ Validators.required, Validators.pattern(this.validaEmail) ]),
cpf: new FormControl('', [ Validators.required, this.validaCpf ]),
telefone: new FormControl('', [ Validators.required ]),
cep: new FormControl('', [ Validators.required, Validators.pattern(this.validaCep) ])
});
}
Tentativa de mascara...
// Mascaras
cpfMask = [/\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, '.', /\d/, /\d/, /\d/, '-', /\d/, /\d/];
cepMask = [/\d/, /\d/, /\d/, /\d/ , /\d/, '-', /\d/, /\d/, /\d/];
telefoneMask = function(){
if(this.myForm.controls.telefone.value.length === 9){
[/\d/, /\d/, /\d/, /\d/ , /\d/, '-', /\d/, /\d/, /\d/, /\d/];
}else{
[/\d/, /\d/, /\d/, /\d/ , '-', /\d/, /\d/, /\d/, /\d/, /\d/];
}
}
constructor(fb: FormBuilder, public router: Router, private vwServicePagination: VwServicePagination){
//Grupo de formulario - Validações
this.myForm = fb.group({
nome: new FormControl('', [ Validators.required, Validators.minLength(2), this.validaNome ]),
email: new FormControl('', [ Validators.required, Validators.pattern(this.validaEmail) ]),
cpf: new FormControl('', [ Validators.required, this.validaCpf ]),
telefone: new FormControl('', [ Validators.required ]),
cep: new FormControl('', [ Validators.required, Validators.pattern(this.validaCep) ])
});
}