mareczek/international-phone-number

how to get selected country code ?

arafathnihar opened this issue · 5 comments

how to get selected country code ?

@arafathnihar Did you find the country code ? I have the same question.

@nicolasrosado Try this
angular.element("#phone_number_input").intlTelInput("getSelectedCountryData").dialCode;

Thanks for your reactivity @arafathnihar !
So the dial code is not exposed by the angular library ...
Your solution is useful to retrieve the information of dial code but if we want to set the variable it's dirty.
The variable should be exposed by the library to avoid a dirty/custom solution.

After analyse the library, I suppose that the selected country is exposed in country variable directive scope :
scope: {
ngModel: '=',
country: '='
},

Netherless, when I try to bind the selected country with an external variable, I don't retrieve it.

with bound country. Useful when you have external contries control:
<input type="text" international-phone-number only-countries ng-model="phone" country="country">

Do you have an example to retrieve the selected country ?

It seems to be like this :
selectedCountry = {
areaCodes: null,
dialCode: "508",
iso2: "pm",
name: "Saint Pierre and Miquelon (Saint-Pierre-et-Miquelon)",
priority: 0
};

@Romakita
Any idea ?