international-phone-number icon indicating copy to clipboard operation
international-phone-number copied to clipboard

how to get selected country code ?

Open arafathnihar opened this issue 8 years ago • 5 comments

arafathnihar avatar Dec 12 '16 11:12 arafathnihar

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

nicolasrosado avatar Apr 20 '17 09:04 nicolasrosado

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

arafathnihar avatar Apr 20 '17 10:04 arafathnihar

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.

nicolasrosado avatar Apr 20 '17 10:04 nicolasrosado

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 };

nicolasrosado avatar Apr 26 '17 09:04 nicolasrosado

@Romakita Any idea ?

nicolasrosado avatar Apr 26 '17 15:04 nicolasrosado