mareczek / international-phone-number

AngularJS directive implementing intl-tel-input (https://github.com/Bluefieldscom/intl-tel-input)

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

how to get selected country code ?

arafathnihar opened this issue · comments

@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 ?