From 2aaf46b4c9382453e732eb25d8f3d435cf9d8e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20M=C3=BCller?= Date: Thu, 1 Sep 2016 21:34:21 +0200 Subject: [PATCH] refactor(core): add module file --- src/core/core-module.ts | 39 +++++++++++++++++++++++++++++++++++++++ src/core/index.ts | 37 ++----------------------------------- 2 files changed, 41 insertions(+), 35 deletions(-) create mode 100644 src/core/core-module.ts diff --git a/src/core/core-module.ts b/src/core/core-module.ts new file mode 100644 index 000000000..43ecc5f66 --- /dev/null +++ b/src/core/core-module.ts @@ -0,0 +1,39 @@ +import {ModuleWithProviders, NgModule, Provider, provide} from '@angular/core'; + +import {SebmGoogleMap} from './directives/google-map'; +import {SebmGoogleMapCircle} from './directives/google-map-circle'; +import {SebmGoogleMapInfoWindow} from './directives/google-map-info-window'; +import {SebmGoogleMapMarker} from './directives/google-map-marker'; +import {SebmGoogleMapPolyline} from './directives/google-map-polyline'; +import {SebmGoogleMapPolylinePoint} from './directives/google-map-polyline-point'; +import {LazyMapsAPILoader} from './services/maps-api-loader/lazy-maps-api-loader'; +import {LazyMapsAPILoaderConfigLiteral, provideLazyMapsAPILoaderConfig} from './services/maps-api-loader/lazy-maps-api-loader'; +import {MapsAPILoader} from './services/maps-api-loader/maps-api-loader'; +import {BROWSER_GLOBALS_PROVIDERS} from './utils/browser-globals'; + +const CORE_DIRECTIVES: any[] = [ + SebmGoogleMap, SebmGoogleMapMarker, SebmGoogleMapInfoWindow, SebmGoogleMapCircle, + SebmGoogleMapPolyline, SebmGoogleMapPolylinePoint +]; + +/** + * The angular2-google-maps core module. Contains all Directives/Services/Pipes + * of the core module. Please use `AgmCoreModule.forRoot()` in your app module. + */ +@NgModule({declarations: CORE_DIRECTIVES, exports: CORE_DIRECTIVES}) +export class AgmCoreModule { + /** + * Please use this method when you register the module at the root level. + */ + static forRoot(lazyMapsAPILoaderConfig?: LazyMapsAPILoaderConfigLiteral): ModuleWithProviders { + const providers: Provider[] = + [...BROWSER_GLOBALS_PROVIDERS, provide(MapsAPILoader, {useClass: LazyMapsAPILoader})]; + if (lazyMapsAPILoaderConfig) { + providers.push(provideLazyMapsAPILoaderConfig(lazyMapsAPILoaderConfig)); + } + return { + ngModule: AgmCoreModule, + providers: providers, + }; + } +} diff --git a/src/core/index.ts b/src/core/index.ts index 57f715443..512465dbb 100644 --- a/src/core/index.ts +++ b/src/core/index.ts @@ -1,15 +1,3 @@ -import {ModuleWithProviders, NgModule, provide} from '@angular/core'; - -import {SebmGoogleMap} from './directives/google-map'; -import {SebmGoogleMapCircle} from './directives/google-map-circle'; -import {SebmGoogleMapInfoWindow} from './directives/google-map-info-window'; -import {SebmGoogleMapMarker} from './directives/google-map-marker'; -import {SebmGoogleMapPolyline} from './directives/google-map-polyline'; -import {SebmGoogleMapPolylinePoint} from './directives/google-map-polyline-point'; -import {LazyMapsAPILoader} from './services/maps-api-loader/lazy-maps-api-loader'; -import {MapsAPILoader} from './services/maps-api-loader/maps-api-loader'; -import {BROWSER_GLOBALS_PROVIDERS} from './utils/browser-globals'; - // main modules export * from './directives'; export * from './services'; @@ -18,26 +6,5 @@ export * from './map-types'; // Google Maps types export {LatLngBounds, LatLng, LatLngLiteral, MapTypeStyle} from './services/google-maps-types'; -const GOOGLE_MAPS_PROVIDERS: any[] = [ - BROWSER_GLOBALS_PROVIDERS, - provide(MapsAPILoader, {useClass: LazyMapsAPILoader}), -]; - -const CORE_DIRECTIVES: any[] = [ - SebmGoogleMap, SebmGoogleMapMarker, SebmGoogleMapInfoWindow, SebmGoogleMapCircle, - SebmGoogleMapPolyline, SebmGoogleMapPolylinePoint -]; - -/** - * The angular2-google-maps core module. Contains all Directives/Services/Pipes - * of the core module. Please use `AgmCoreModule.forRoot()` in your app module. - */ -@NgModule({declarations: CORE_DIRECTIVES, exports: CORE_DIRECTIVES}) -export class AgmCoreModule { - static forRoot(): ModuleWithProviders { - return { - ngModule: AgmCoreModule, - providers: GOOGLE_MAPS_PROVIDERS, - }; - } -} +// core module +export * from './core-module';