fix(config): pass custom providers in the bootstrap of the app

references #6685
This commit is contained in:
Brandy Carney
2016-06-01 17:15:37 -04:00
parent 7e4b13daaf
commit c74b3f7422
2 changed files with 28 additions and 7 deletions

View File

@ -1,7 +1,26 @@
import {Component} from '@angular/core';
import {ionicBootstrap, NavController, Modal, ViewController} from '../../../../../src';
import {Injectable} from '@angular/core';
@Injectable()
export class SomeData {
constructor() {}
getData() {
return "SomeData";
}
}
@Injectable()
export class OtherData {
constructor() {}
getData() {
return "OtherData";
}
}
@Component({
template: `
<ion-toolbar>
@ -37,7 +56,10 @@ class Page1 {
page2 = Page2;
sort: string = 'all';
constructor(private nav: NavController) {}
constructor(private nav: NavController, private someData: SomeData, private otherData: OtherData) {
console.log("Got some data from", someData.getData());
console.log("Got some data from", otherData.getData());
}
goToTabs() {
this.nav.push(TabsPage);
@ -119,6 +141,6 @@ class E2EApp {
root = Page1;
}
ionicBootstrap(E2EApp, null, {
ionicBootstrap(E2EApp, [SomeData, OtherData], {
statusbarPadding: true
});

View File

@ -56,13 +56,11 @@ export function ionicPostBootstrap(ngComponentRef: ComponentRef<any>): Component
return ngComponentRef;
}
export function ionicProviders(customProviders?: Array<any>, config?: any): any[] {
// add custom providers to Ionic's dev
let directives = IONIC_DIRECTIVES;
if (customProviders) {
directives.push(customProviders);
}
// add custom providers to Ionic's app
customProviders = isPresent(customProviders) ? customProviders : [];
// create an instance of Config
if (!(config instanceof Config)) {
@ -109,6 +107,7 @@ export function ionicProviders(customProviders?: Array<any>, config?: any): any[
ROUTER_PROVIDERS,
provide(LocationStrategy, {useClass: HashLocationStrategy}),
HTTP_PROVIDERS,
customProviders
];
}