angular-material-extensions / select-country

Angular Material component that allow users to select a country or nationality with an autocomplete feature
https://angular-material-extensions.github.io/select-country/
MIT License
126 stars 40 forks source link

Value initialization with language input does not work #146

Closed Mark-Durkot closed 5 months ago

Mark-Durkot commented 5 months ago

Hello guys, great component, enjoy using it. But I encountered an issue. When I define the component with [language] and [formControl]/[value] inputs, the language sets correctly but the default value fails.

<mat-select-country [formControl]="formControl" [language]="'uk'"></mat-select-country>

After executing formControl.patchValue({ alpha2Code: 'UK' }) the flag of that country renders, but the name still fails to set. I also encountered this with [value]='defaultValue' (where defaultValue is type Country).

<mat-select-country [value]="defaultValue" [language]="'uk'"></mat-select-country> defaultValue: Country = { alpha2Code: 'UK' }

Mark-Durkot commented 5 months ago

After playing around, I found out that it works fine using a FormGroup and accessing the value through formControlName:

form = new FormGroup({ 
    country: new FormControl<Country>({ alpha2Code: 'UK' })
});
<form [formGroup]="form">
    <mat-select-country 
        formControlName="country" 
        [language]="'uk'"
    ></mat-select-country>
</form>
wlucha commented 4 months ago

For me this issue still persists. If language is set, the country cannot be initially set.