我正在尝试在我的选择框中添加默认国家标志(印度(。我正在使用Angular 4国际手机前缀输入框。但是我找不到如何设置默认值。他们在github上分享了文档
@input((语言环境可以为ISO 639-1语言代码设置可用语言:ES:西班牙语,EN:English
@input((DefaultCountry可以提供ISO 639-1国家代码以设置选定的默认国家。
我已经尝试过,但是它不起作用。
<int-phone-prefix formControlName="myPhone" [locale]="'hi'" [defaultCountry]="in"> </int-phone-prefix>
我正在使用NG4-Intl-Phone软件包,请帮助我对此问题进行排序
尝试defaultCountry而无需属性绑定,因为 in
是您的字符串而不是动态内容,因此请尝试此
<int-phone-prefix formControlName="myPhone" [locale]="'hi'" defaultCountry="in"> </int-phone-prefix>
或
<int-phone-prefix formControlName="myPhone" [locale]="'hi'" [defaultCountry]="'in'"> </int-phone-prefix>
HTML
```
<mat-form-field class="pd-mat-form-field-class" hideRequiredMarker>
<label class="pd-mat-custom-label">{{"CELL_1" | translate }}</label>
<mat-label></mat-label>
<input ng2TelInput #intlInput
[ng2TelInputOptions]="cell1TelInput"
(hasError)="hasError1($event)"
(ng2TelOutput)="getNumberCellNo1($event)"
(intlTelInputObject)="cell1telInputObject($event)"
(countryChange)="onCell1CountryChange($event)"
type="text"
maxlength=14 class="pd-mat-form-input-margin"
matInput name="cell_no1"
formControlName = "cellnumber1" required>
`</mat-form-field>`
```
Javascript
`
```
cell1TelInput = {
initialCountry: 'za', //default country
autoPlaceholder: 'polite',
nationalMode :true,
customPlaceholder: function(selectedCountryPlaceholder) {
return 'Example : ' + selectedCountryPlaceholder;
}
if (response.userCellNumbers[0] && response.userCellNumbers[0].cell_no) {
this.cellnumber1 = response.userCellNumbers[0].cell_no;
this.cell_code1.setNumber(this.cellnumber1)
}
getNumberCellNo1(e:any)
{
this.cell_code1.setNumber(e)
this.cellnumber1=e
}
public onCell1CountryChange(e: any) {
this.cellnumber1DialCode = e.dialCode;
this.cell1TelInput.initialCountry = e.iso2
this.cell_code1.setNumber("")
}
public cell1telInputObject(obj) {
this.cell_code1=obj
}
hasError1(event: any): void {
if (!event && this.uploadForm.value.cellnumber1 ) {
this.uploadForm.get('cellnumber1').setErrors(['invalid_cell_phone', true]);
}
}
if (this.uploadForm.value.cellnumber1) {
this.uploadForm.value.cellnumber1 = this.cellnumber1
this.cellNumbers.push( {"cell_no": this.uploadForm.value.cellnumber1.replace(/s/g, ""), "cell_type": 1});
}`
```
hasError() is used for validation
The getNumber() will give you the country code and number as +919843133490.
The setNumber() will set the country flag and place the number in input field.
ng2TelInputOptions is used to initialize data
Hope it helped. Any further queries can be asked.