Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to change preferred country #154

Open
egilsd opened this issue May 10, 2022 · 2 comments
Open

Unable to change preferred country #154

egilsd opened this issue May 10, 2022 · 2 comments

Comments

@egilsd
Copy link

egilsd commented May 10, 2022

Im trying to set the preferred country depending on what i get back from the ip address. Im checking the users IP in the afterViewInit to get the country the user is in. Im trying to set that country as the preferred country for the ngx-mat-intl-tel-input component instead of hardcoding it in.
Any suggestions as to how to make that possible?

I tried making an observable and async it, but that doesnt seem to work here unfortunately.

@pavlikxor
Copy link
Contributor

Unfortunately current implementation doesn't accept any on-changes handler for an input property preferredCountries.
I guess in such case the only way is to fire ChangeDetectorRef once you have the new set of countries ready.

@Zetanova
Copy link

Zetanova commented Oct 1, 2022

@pavlikxor ChnageDetectorRef does not work

To set preferredCountriesInDropDown and/or selectedCountry is working

export class MuchbetterComponent {
      @ViewChild('phone') phoneElement!:NgxMatIntlTelInputComponent;

       //.... 
        
      setCountry(country:string) {
           const iso2 = country.toLowerCase();
          const foundCountry = this.phoneElement.allCountries.find(n => n.iso2 == iso2);
          if(foundCountry)
          {
            this.phoneElement.preferredCountriesInDropDown = [foundCountry];
            this.phoneElement.selectedCountry = foundCountry;
          }
      }
 
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants