fix(angular): setup config provider correctly

This commit is contained in:
mhartington
2018-05-01 08:50:49 -05:00
committed by Manu MA
parent ae1028d91e
commit 82fbe3191a
4 changed files with 2849 additions and 23 deletions

2831
angular/package-lock.json generated

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core'; import { ModuleWithProviders, NgModule } from '@angular/core';
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import * as c from './directives'; import * as c from './directives';
@ -6,7 +6,6 @@ import * as d from './directives/proxies';
import * as p from './providers'; import * as p from './providers';
import { setupConfig } from '@ionic/core'; import { setupConfig } from '@ionic/core';
const DECLARATIONS = [ const DECLARATIONS = [
// proxies // proxies
d.App, d.App,
@ -107,7 +106,7 @@ const DECLARATIONS = [
c.VirtualFooter, c.VirtualFooter,
c.VirtualHeader, c.VirtualHeader,
c.VirtualItem, c.VirtualItem,
c.VirtualScroll, c.VirtualScroll
]; ];
const PROVIDERS = [ const PROVIDERS = [
@ -120,30 +119,28 @@ const PROVIDERS = [
p.NavController, p.NavController,
p.Platform, p.Platform,
p.Events, p.Events,
p.DomController, p.DomController
p.Config
]; ];
@NgModule({ @NgModule({
declarations: DECLARATIONS, declarations: DECLARATIONS,
exports: DECLARATIONS, exports: DECLARATIONS,
providers: [ providers: [p.AngularDelegate, p.ModalController, p.PopoverController],
p.AngularDelegate, imports: [CommonModule]
p.ModalController,
p.PopoverController,
],
imports: [
CommonModule,
]
}) })
export class IonicModule { export class IonicModule {
static forRoot(config?: {[key: string]: any}): ModuleWithProviders { static forRoot(config?: { [key: string]: any }): ModuleWithProviders {
setupConfig(config);
return { return {
ngModule: IonicModule, ngModule: IonicModule,
providers: PROVIDERS providers: [
...PROVIDERS,
{ provide: p.ConfigToken, useValue: config },
{
provide: p.Config,
useFactory: setupConfig,
deps: [p.ConfigToken, p.Platform]
}
]
}; };
} }
} }
export const ConfigToken = new InjectionToken<any>('USERCONFIG');

View File

@ -1,7 +1,6 @@
import { Config as CoreConfig } from '@ionic/core'; import { Config as CoreConfig } from '@ionic/core';
import { Injectable } from '@angular/core'; import { InjectionToken } from '@angular/core';
@Injectable()
export class Config { export class Config {
get(key: string, fallback?: any): any { get(key: string, fallback?: any): any {
@ -21,6 +20,8 @@ export class Config {
} }
} }
export const ConfigToken = new InjectionToken<any>('USERCONFIG');
function getConfig(): CoreConfig { function getConfig(): CoreConfig {
const Ionic = (window as any).Ionic; const Ionic = (window as any).Ionic;
if (Ionic && Ionic.config) { if (Ionic && Ionic.config) {

View File

@ -1,4 +1,3 @@
export { AngularDelegate } from './angular-delegate'; export { AngularDelegate } from './angular-delegate';
export { ActionSheetController } from './action-sheet-controller'; export { ActionSheetController } from './action-sheet-controller';
export { AlertController } from './alert-controller'; export { AlertController } from './alert-controller';
@ -12,4 +11,4 @@ export { PopoverController } from './popover-controller';
export { ToastController } from './toast-controller'; export { ToastController } from './toast-controller';
export { NavController } from './nav-controller'; export { NavController } from './nav-controller';
export { DomController } from './dom-controller'; export { DomController } from './dom-controller';
export { Config } from './config'; export { Config, ConfigToken } from './config';