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

Default country doesn't work #77

Open morrowyn opened 3 years ago

morrowyn commented 3 years ago

Hi,

I'm trying to set the default country as such. But the field stays empty: component.ts

this.currentCountry = {alpha2Code:'DE', alpha3Code:null, callingCode:null, name:null, numericCode:null};

component.html

<mat-select-country appearance="outline"
                          label="Country"
                          formControlName="country"
                          [value]="currentCountry"
                          (onCountrySelected)="onCountrySelected($event)">
            </mat-select-country>

output: image

The documentation specified I should: pass an empty Country object with alpha2 code populated to do alpha2 lookup)

Any idea what is wrong with my code?

Btw. Im using the following versions: angular 12 @angular-material-extensions/select-country": "^5.0.1" "svg-country-flags": "^1.2.10"

MoAsmar commented 3 years ago

I faced the same issue, please update any fix soon @AnthonyNahas ?

MoAsmar commented 3 years ago

I suggest to make the value field require only 1 value from Country Model, which is for example alpha2Code or numericCode

simionrobert commented 3 years ago

For anyone who has a difficult time in setting the default country in reactive forms, setting only alpha2Code should work:

  this.identityCardFormGroup = this._formBuilder.group({
      taraEmiterii: [{ alpha2Code: 'RO' }, Validators.required],
      ...
    });