Skip to content

Commit

Permalink
fix(angular): Config provider
Browse files Browse the repository at this point in the history
  • Loading branch information
manucorporat committed Apr 26, 2018
1 parent 98a3519 commit 329a348
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 23 deletions.
15 changes: 4 additions & 11 deletions angular/src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { CommonModule } from '@angular/common';
import * as c from './directives';
import * as d from './directives/proxies';
import * as p from './providers';
import { setupConfig } from '@ionic/core';


const DECLARATIONS = [
Expand Down Expand Up @@ -120,6 +121,7 @@ const PROVIDERS = [
p.Platform,
p.Events,
p.DomController,
p.Config
];

@NgModule({
Expand All @@ -136,21 +138,12 @@ const PROVIDERS = [
})
export class IonicModule {
static forRoot(config?: {[key: string]: any}): ModuleWithProviders {
setupConfig(config);
return {
ngModule: IonicModule,
providers: [
// Load config with defualt values
{ provide: ConfigToken, useValue: config },
{ provide: p.Config, useFactory: setupConfig, deps: [ ConfigToken ] },

...PROVIDERS,
]
providers: PROVIDERS
};
}
}

export const ConfigToken = new InjectionToken<any>('USERCONFIG');
export function setupConfig(userConfig: any): p.Config {
const config = new p.Config(userConfig);
return config;
}
14 changes: 2 additions & 12 deletions angular/src/providers/config.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import { Config as CoreConfig } from '@ionic/core';
import { Injectable } from '@angular/core';

@Injectable()
export class Config {

constructor(defaultConfig: {[key: string]: any}) {
const Ionic = (window as any).Ionic;
if (Ionic.config && Ionic.config.constructor.name !== 'Object') {
console.error('ionic config was already initialized');
return;
}
Ionic.config = {
...Ionic.config,
...defaultConfig
};
}

get(key: string, fallback?: any): any {
return getConfig().get(key, fallback);
}
Expand Down

0 comments on commit 329a348

Please sign in to comment.