Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Shortcut for configuring LazyMapsAPILoader #388

Closed
sebholstein opened this issue Jun 5, 2016 · 3 comments
Closed

feat: Shortcut for configuring LazyMapsAPILoader #388

sebholstein opened this issue Jun 5, 2016 · 3 comments
Assignees

Comments

@sebholstein
Copy link
Owner

To set a Google Maps API key, you have to write the following code today:

import {provide} from 'angular2/core';
import {ANGULAR2_GOOGLE_MAPS_PROVIDERS, LazyMapsAPILoaderConfig} from 'angular2-google-maps/core';

bootstrap(AppComponent, [
  ANGULAR2_GOOGLE_MAPS_PROVIDERS,
  provide(LazyMapsAPILoaderConfig, {useFactory: () => {
    let config = new LazyMapsAPILoaderConfig();
    config.apiKey = 'mykey';
    return config;
  }})
])

As this is very verbose, we should add this shortcut, as adding an API key is a very common case:

import {provide} from 'angular2/core';
import {ANGULAR2_GOOGLE_MAPS_PROVIDERS, googleMapsAPIKey} from 'angular2-google-maps/core';

bootstrap(AppComponent, [
  ANGULAR2_GOOGLE_MAPS_PROVIDERS,
  googleMapsAPIKey('myKey')
])
@jhuntoo
Copy link

jhuntoo commented Jun 7, 2016

How about

import {provide} from 'angular2/core';
import {provideGoogleMaps} from 'angular2-google-maps/core';

bootstrap(AppComponent, [
  provideGoogleMaps({ apiKey: 'myKey' })
])

Which returns an array including ANGULAR2_GOOGLE_MAPS_PROVIDERS and the config object.

It's even more concise, and the "options-style" object could be extended when/if more configuration is needed down the line.

@sebholstein
Copy link
Owner Author

sebholstein commented Jun 8, 2016

You gave me food for thought :)

I researched how other angular 2 related libraries handle the providers stuff. I discovered the angularfire2 and really makes sense to me:

https://github.com/angular/angularfire2/blob/master/docs/5-user-authentication.md#configure-application-in-bootstrap

So I propose this way:

import {provide} from 'angular2/core';
import {lazyMapsAPILoaderConfig} from 'angular2-google-maps/core';

bootstrap(AppComponent, [
  GOOGLE_MAPS_PROVIDERS,
  lazyMapsAPILoaderConfig({ apiKey: 'myKey' })
])

@jhuntoo
Copy link

jhuntoo commented Jun 8, 2016

Yeah I like that too - it's clean & clear API!

@sebholstein sebholstein changed the title feat: Shortcut for setting a Google Maps API key feat: Shortcut for configuring LazyMapsAPILoader Jun 8, 2016
@sebholstein sebholstein self-assigned this Jun 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants