question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Lazy-maps-api-loader error

See original GitHub issue

Hi @SebastianM ,

I am using angular2-google-maps in ionic2/angular2 in which we need the map only in one page and it works fine too, but every consecutive visit to the same page gives me an error.

You have included the Google Maps API multiple times on this page. This may cause unexpected errors.

Please let me know if i am missing something.

Thanks

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (3 by maintainers)

github_iconTop GitHub Comments

23reactions
efstathiosntonascommented, Jan 17, 2017

In your app.module.ts imports add:

AgmCoreModule.forRoot({ apiKey: 'xxxxxx', libraries: ['places'] })

(ofcourse you can remove libraries: [‘places’])

and then in a shared module add: in imports AgmCoreModule and in exports: AgmCoreModule

then the You have included the Google Maps API multiple times on this page. This may cause unexpected errors. will be gone

20reactions
IAMtheIAMcommented, Mar 24, 2017

@szykov The solution to using this angular2 component in a lazy loaded submodule is to do what @efstathiosntonas said

First, in your main app.module.ts, include the api

// app.module.ts
import { AgmCoreModule } from 'angular2-google-maps/core';

//other stuff here

@NgModule({
   bootstrap: [AppComponent],
   declarations: [ //  declarations contains: components, directives and pipes],
   imports: [ // import other modules here
        AgmCoreModule.forRoot({
            apiKey: 'YOUR_KEY'
       })],
   providers: [ // expose our Services and Providers into Angular's dependency injection]
})

Then inside your submodule, include it again but without the API key

// maps.module.ts (submodule)
import { AgmCoreModule } from 'angular2-google-maps/core';

// other stuff

@NgModule({
   imports: [ // other imports here
      AgmCoreModule
   ],
   declarations: [ // Components / Directives / Pipes
      MapComponent
   ]
})

Now it will lazy load the angular2 maps component and only request the javascript once. I did this using webpack 2 and it works fine. Thanks guys for the good work here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

LazyMapsAPILoader is broken since 1.0.0 #1726 - GitHub
Hi,. Using a lazily-provided API key worked fine with 1.0.0-beta.7, but today (with version 1.0.0) it creates a compilation error: ERROR in app/ ......
Read more >
loader - @agm/core
_assignScriptLoadingPromise(scriptElem: HTMLElement). Defined in packages/core/src/lib/services/maps-api-loader/lazy-maps-api-loader.ts:127. Parameters : ...
Read more >
Errors installing google maps - Google Groups
I'm trying to install angular 2 google maps with the latest version of angular2 (rc4) and I`m constantly getting errors when installing it...
Read more >
Load googlemaps api before AGM Map - Stack Overflow
The problem arises because the AgmCoreModule in the app.module takes care of loading the Google API like so: AgmCoreModule.
Read more >
SebastianM/angular2-google-maps - Gitter
i have also changed LazyMapsAPILoader to MapsAPILoader like brunsten mention ... Maps API warning: NoApiKeys and Google Maps API error: MissingKeyMapError.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found