mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-21 21:15:24 +08:00
fix(config): pass custom providers in the bootstrap of the app
references #6685
This commit is contained in:
@ -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
|
||||
});
|
||||
|
@ -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
|
||||
];
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user