Angular 8 input phone number with country codeAngular 8 input phone number with country code

Hello to all, welcome to therichpost.com. In this post, I will tell you, Angular 8 input phone number with country code.

Guy’s this post code snippet will also work in angular latest version Angular 17 input type phone number with country code and country flags.

Angular 8 input phone number with country code
Angular 8 input phone number with country code
Angular Input with Country Code Working Video

Guys click here to see the updated version of this post for Angular 11+ versions.

Post Working:

In this post, I am showing input field with enter phone number with country code and country flags.

Here is the working coding steps and please follow carefully:

1. Here are the basics commands to install angular 17 on your system:

npm install -g @angular/cli 

ng new angularpopup //Create new Angular Project

cd angularpopup // Go inside the Angular Project Folder

ng serve --open // Run and Open the Angular Project

http://localhost:4200/ // Working Angular Project Url

2. Here is the below command you need to run into your terminal to add intl tel input into your angular 8 application:

npm install ng2-tel-input intl-tel-input --save

3. Now you need to add below code into your angular.json file:

...
"styles": ["node_modules/intl-tel-input/build/css/intlTelInput.css"],
"scripts": ["node_modules/intl-tel-input/build/js/intlTelInput.min.js"]
...

4. Now you need to add below code into your src/app/app.module.ts file:

...
import {Ng2TelInputModule} from 'ng2-tel-input';
...

imports: [...  Ng2TelInputModule ...]

5. Now you need to add below code into your src/app/app.component.html file:

<input type="text" ng2TelInput />

This is it guy’s and if you will have any kind of query related to this post then feel free to comment below.

Note: Friends, In this post, I just tell the basic setup and things, you can change the code according to your requirements.

Jassa

Thank you

By therichpost

Hello to all. Welcome to therichpost.com. Myself Ajay Malhotra and I am freelance full stack developer. I love coding. I know WordPress, Core php, Angularjs, Angular 19, MedusaJs, Next.js, Bootstrap 5, Nodejs, Laravel, Codeigniter, Shopify, Squarespace, jQuery, Google Map Api, Vuejs, Reactjs, Big commerce etc.

69 thoughts on “Angular 8 input phone number with country code”
  1. Hi , I the code you provided above is working properly, if you have src/app/app.component.ts code sp, please share with me.

  2. Do we need to define some code on app.component.ts too you should also mention that code in order to make it complete

  3. Hello,
    I have been trying to do it as well but I am getting error in my angular 9 project and also I have checked npm packages all documentation . After all I am getting same error . Error : this .telInput is undefine. some times it show like this . telInput in not a function . Tell me the solution What will I do for solving this problem. Why I am facing this type of error.

    and I have seen your toast posted too and after doing all I am not getting the toast design but it’s working. What should I do to solve it?

  4. this is the initial set but when I update or add like I choose the “butan” country and save it then I checked or update the “butan” will not be saved.so how to save the country flag in the form.

  5. How to get both country code values and mobile number and validate
    also how to how country code dropdown in edit mode when user choose number according to country

  6. Hi Ajay, when i make the then its giving me below error-

    ERROR DOMException: Failed to execute ‘setSelectionRange’ on ‘HTMLInputElement’: The input element’s type (‘number’) does not support selection.

    and cant able to store the data in backed because of this error, can you help me how to resolve this problem?
    i want to accept the mobile number type as a number not a text?(in tutorial you make input type=”text”)
    can you help me with this?

  7. typo mistake ,correction** –>

    when i make–> input type = “number” then getting above error

  8. Hello, thanks for the code you shared.
    I want to control the size but I am unable to.
    Also, how do I set another country as default?

  9. The quote mark used is what caused the error so I changed to this:
    [ng2TelInputOptions]=”{initialCountry: ‘us’}”

  10. hello, This is working perfectly. but the background is transparent. and other buttons are shown above the drop-down list. is there any way to customize it?

    Thanks

  11. any idea if this will work without bootstrap ?
    because i tried to implement it in my project and its just an empty input

  12. hello can you help me to fnid the way that make me connect the APi fonction with angular

  13. How to bind the extension along with the phone number, and then send it to a post request? Only the typed in number is send. But I need to send the number along with the extension

  14. Hai,
    please help me one this , how can i get separate country flag and separate county code .

  15. This is great Ajay, you saved my day. The code works perfectly fine. But there is use case when you are getting the country code from server and setting that using event.setCountry(this.countryID);
    It doesn’t work. Becuase it populate the select boxes before getting the data from API. What do you suggest for that.

  16. how can I append the country code with the telephone number. I’m working on aa angular reactive form. I want to pass the entire value on submit.
    ex:
    when I select Sri lankan flag from the dropdown it doesn’t append to the phone number

  17. Thanks for this code.. How can I get the country code to save in DB? and associate to the correct flag when show the number?

  18. hey thank you for your help it is working,
    i want to know how can excludes some countries or add countries

  19. hi bro, can you please tell me how to change the prefered country ?

  20. Hi, I am getting ERROR TypeError: window.intlTelInput is not a function, How to Fix this error.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.