首页 > 解决方案 > 以角度 10 提交表单后无法清除 ngx-mat-intl-tel-input

问题描述

      <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>

在提交表单时,我无法清除 ngx mat intl tel 输入,除电话字段外,其他输入字段都被清除。在此处输入图像描述

标签: javascriptangularformstypescript-typings

解决方案


您可以尝试手动清除输入。例如:

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

然后是这样的:

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

推荐阅读