Dhe*_*mar 5 intl-tel-input angular
我在 Angular 项目中使用 ngx-intl-tel-input 进行电话号码验证。
<form #f="ngForm" [formGroup]="phoneForm">
<ngx-intl-tel-input
[cssClass]="'custom'"
[preferredCountries]="['us', 'gb']"
[enablePlaceholder]="true"
[enableAutoCountrySelect]="true"
[value]="'+91 8888888888'"
name="phone"
formControlName="phone"></ngx-intl-tel-input>
Run Code Online (Sandbox Code Playgroud)
我需要为来自服务器的字段设置值。
我已经使用了[value]属性,但它似乎不起作用。
小智 6
在 ngAfterViewInit 中,将带有国家/地区代码的电话值修补到表单控件并检测更改。
ngAfterViewInit(){
this.phoneForm.controls.phone.setValue('+919898989898');
this.cd.detectChanges();
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9550 次 |
| 最近记录: |