0

How to get country code from input type in Angularjs

I am new in Angularjs, right now I have dropdown of country code + input type text (for mobile number), after a click on submit button, I am getting mobile number successfully but how can I get the country code as well? Here is my HTML code

<input type="tel" class="form-control" id="tel" name="tel" 
       ng-model="updating.phone" ng-intl-tel-input numbers-only
       data-selected-country="selected.country" style="width:100%;">

Here is my script code

function getviewed()
{
    var form = new FormData();
    var numbr = document.getElementById('tel').value;
 }

Editors note:

The GitHub for the ng-intl-tel-input directive is https://github.com/hodgepodgers/ng-intl-tel-input

georgeawg
  • 48,608
  • 13
  • 72
  • 95
amit
  • 1
  • 1
  • 18
  • 28
  • Share country code html and js – sarvon ks May 09 '19 at 12:14
  • You can read here: https://stackoverflow.com/questions/40968069/ngsubmit-is-called-when-press-click-button – Code May 09 '19 at 12:15
  • Looks like it is bound to `selected.country` – Igor May 09 '19 at 13:42
  • BTW if you are not constrained to an existing platform I would strongly recommend learning [angular 7](https://angular.io) (latest as of now) instead as angularjs entered [LTS last year](https://docs.angularjs.org/misc/version-support-status). – Igor May 09 '19 at 13:44
  • When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem. See [How to create a Minimal, Complete, and Verifiable example](https://stackoverflow.com/help/mcve). – georgeawg May 09 '19 at 14:01
  • @Igor If one wants to learn a framework that is not End-of-Life, there are better choices than Angular 7. – georgeawg May 09 '19 at 14:25

1 Answers1

0

Try this:

angular.element("#tel").intlTelInput.getSelectedCountryData()
Elena Roman
  • 137
  • 8