【问题标题】:Unable to clear the ngx-mat-intl-tel-input after form submit in angular 10以角度 10 提交表单后无法清除 ngx-mat-intl-tel-input
【发布时间】:2021-02-10 15:05:11
【问题描述】:
      <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 输入,除电话字段外,其他输入字段均被清除。

【问题讨论】:

    标签: javascript angular forms typescript-typings


    【解决方案1】:

    试试这个

    .TS 文件

    @ViewChild('phoneNumber') phone: FormControl`
    
    yourResetMethod(){
    this.phone.reset();
    }
    

    【讨论】:

      【解决方案2】:

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

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

      然后是这样的:

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

      【讨论】:

        猜你喜欢
        • 2021-01-03
        • 1970-01-01
        • 2020-03-15
        • 2021-04-10
        • 2017-06-14
        • 2019-08-22
        • 2020-09-24
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多