Skip to content
Get the country code from a service based on MapsAPILoader and browser navigator
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.


In typescript working with angular 6,
i needed to make a async function which respond with current countryCode based on users geoLocation.
So here I am using nevigator get the current lat lng.
Its not possible to get the country code directly from nevigator. SO i needed googleMapsApi
By using import { MapsAPILoader } from '@agm/core';
I am able to get the address_components from google responce and filtering it to get the current country Short name.
This i a going to use in 
ng2TelInput =>
which is used to add dial code in phone number but requires country code to auto populate.

User below async function to upadte any typescript variable.
In my login component

country_code:any = 'US';

ngOnInit() {

async getCurrentCountry(){
  this.country_code = await;

You can’t perform that action at this time.