【问题标题】: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 = '';
}
}