Skip to content

Commit

Permalink
fix(angular): setup config provider correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
mhartington authored and manucorporat committed May 7, 2018
1 parent ae1028d commit 82fbe31
Show file tree
Hide file tree
Showing 4 changed files with 2,849 additions and 23 deletions.
2,831 changes: 2,830 additions & 1 deletion angular/package-lock.json

Large diffs are not rendered by default.

33 changes: 15 additions & 18 deletions angular/src/module.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { InjectionToken, ModuleWithProviders, NgModule } from '@angular/core';
import { ModuleWithProviders, NgModule } from '@angular/core';
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 = [
// proxies
d.App,
Expand Down Expand Up @@ -107,7 +106,7 @@ const DECLARATIONS = [
c.VirtualFooter,
c.VirtualHeader,
c.VirtualItem,
c.VirtualScroll,
c.VirtualScroll
];

const PROVIDERS = [
Expand All @@ -120,30 +119,28 @@ const PROVIDERS = [
p.NavController,
p.Platform,
p.Events,
p.DomController,
p.Config
p.DomController
];

@NgModule({
declarations: DECLARATIONS,
exports: DECLARATIONS,
providers: [
p.AngularDelegate,
p.ModalController,
p.PopoverController,
],
imports: [
CommonModule,
]
providers: [p.AngularDelegate, p.ModalController, p.PopoverController],
imports: [CommonModule]
})
export class IonicModule {
static forRoot(config?: {[key: string]: any}): ModuleWithProviders {
setupConfig(config);
static forRoot(config?: { [key: string]: any }): ModuleWithProviders {
return {
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');
5 changes: 3 additions & 2 deletions angular/src/providers/config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { Config as CoreConfig } from '@ionic/core';
import { Injectable } from '@angular/core';
import { InjectionToken } from '@angular/core';

@Injectable()
export class Config {

get(key: string, fallback?: any): any {
Expand All @@ -21,6 +20,8 @@ export class Config {
}
}

export const ConfigToken = new InjectionToken<any>('USERCONFIG');

function getConfig(): CoreConfig {
const Ionic = (window as any).Ionic;
if (Ionic && Ionic.config) {
Expand Down
3 changes: 1 addition & 2 deletions angular/src/providers/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

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

0 comments on commit 82fbe31

Please sign in to comment.