Unable to clear the ngx-mat-intl-tel-input after form submit in angular 10

Viewed 629
      <ngx-mat-intl-tel-input   [preferredCountries]="['in', 'us', 'gb' ]"   [enableSearch]="true"   [enablePlaceholder]="true"
                 #phoneNumber="ngModel" [(ngModel)]="Sms" name = "Sms"  required>
                </ngx-mat-intl-tel-input>

On submit of the form i am not able to clear the ngx mat intl tel input , other input fields are cleared except the tele phone field.enter image description here

2 Answers

Try this

.TS File

@ViewChild('phoneNumber') phone: FormControl`

yourResetMethod(){
this.phone.reset();
}

You could try manually clearing the input. E.g.:

@ViewChild(NgxMatIntlTelInputComponent, {static: true}) phoneInput: NgxMatIntlTelInputComponent;

And then something like:

  if (this.phoneInput) {
    const telInput = document.querySelector(`#${this.phoneInput.id} input[type="tel"]`);
    if (telInput) {
      (<any>telInput).value = '';
    }
  }
Related