Shruthi S N
Shruthi S N

Reputation: 31

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

      <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

Upvotes: 2

Views: 1436

Answers (2)

gmatossian
gmatossian

Reputation: 31

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 = '';
    }
  }

Upvotes: 0

R2B Boondocks
R2B Boondocks

Reputation: 414

Try this

.TS File

@ViewChild('phoneNumber') phone: FormControl`

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

Upvotes: 0

Related Questions