Search code examples
angular8

How to set a mask in component ngx-intl-tel-input


How to define a mask for the phone number according to the format presented by the placeholder attribute of the ngx-intl-tel-input component?


Solution

  • I found a solution for me. My ngx-intl-tel-input component is an angular formControl. So, I used the valueChanges event of this formControl to aply a mask:

    ngOnInit() {
    this.confirmForm = this.formBuilder.group({
      cellPhone: [{ number: this.currentUser.number, countryCode: this.currentUser.countryCode }, [Validators.required]],
      code: ['', [Validators.required, Validators.minLength(6)]],
      id: [this.currentUser.id]
    });
    
    this.confirmForm.get("cellPhone").valueChanges.subscribe(x => {
      //aply the mask
    })}