0

According to Angluar-cli documentation here, I succeed to import any third party library and then to use typings (dt and custom). Youhouou !

But for Google types, I have to prefix all my types by the google.maps namespace :

let geocoder = new google.maps.Geocoder();

What can I do to use short names for types like this :

let geocoder = new Geocoder();

Thanks for any suggestion.

Detail of my Google Maps import are here : Getting started - How to use Google maps api with angular-cli

==== EDIT ====

The @Nikky answer show me the mistake with the google namespace : It will be available at runtime only after the google maps script will be loaded.

So the problem is located in all the constructor() and ngOnInit() that use the google.map types :

  constructor() {
    this.load();                     //will begin goooglemaps script loading
    this.onReady().then(() => {      //subscribtion to script loaded event
      this.geocoder = new google.maps.Geocoder();//'google is not defined' at runtime
    });
  }

1 Answer 1

1

You can import the namespace and assign a name to it

import Geocoder = google.maps.Geocoder;

And then use it as if you were using native Geocoder API

let geocoder = new Geocoder();
Sign up to request clarification or add additional context in comments.

2 Comments

I have an error at runtime : "google is not defined"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.