Skip to content

Commit c74b3f7

Browse files
committed
fix(config): pass custom providers in the bootstrap of the app
references #6685
1 parent 7e4b13d commit c74b3f7

File tree

2 files changed

+28
-7
lines changed

2 files changed

+28
-7
lines changed

src/components/app/test/cordova/index.ts

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,26 @@
11
import {Component} from '@angular/core';
22
import {ionicBootstrap, NavController, Modal, ViewController} from '../../../../../src';
3+
import {Injectable} from '@angular/core';
34

45

6+
@Injectable()
7+
export class SomeData {
8+
constructor() {}
9+
10+
getData() {
11+
return "SomeData";
12+
}
13+
}
14+
15+
@Injectable()
16+
export class OtherData {
17+
constructor() {}
18+
19+
getData() {
20+
return "OtherData";
21+
}
22+
}
23+
524
@Component({
625
template: `
726
<ion-toolbar>
@@ -37,7 +56,10 @@ class Page1 {
3756
page2 = Page2;
3857
sort: string = 'all';
3958

40-
constructor(private nav: NavController) {}
59+
constructor(private nav: NavController, private someData: SomeData, private otherData: OtherData) {
60+
console.log("Got some data from", someData.getData());
61+
console.log("Got some data from", otherData.getData());
62+
}
4163

4264
goToTabs() {
4365
this.nav.push(TabsPage);
@@ -119,6 +141,6 @@ class E2EApp {
119141
root = Page1;
120142
}
121143

122-
ionicBootstrap(E2EApp, null, {
144+
ionicBootstrap(E2EApp, [SomeData, OtherData], {
123145
statusbarPadding: true
124146
});

src/config/bootstrap.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,13 +56,11 @@ export function ionicPostBootstrap(ngComponentRef: ComponentRef<any>): Component
5656
return ngComponentRef;
5757
}
5858

59-
6059
export function ionicProviders(customProviders?: Array<any>, config?: any): any[] {
61-
// add custom providers to Ionic's dev
6260
let directives = IONIC_DIRECTIVES;
63-
if (customProviders) {
64-
directives.push(customProviders);
65-
}
61+
62+
// add custom providers to Ionic's app
63+
customProviders = isPresent(customProviders) ? customProviders : [];
6664

6765
// create an instance of Config
6866
if (!(config instanceof Config)) {
@@ -109,6 +107,7 @@ export function ionicProviders(customProviders?: Array<any>, config?: any): any[
109107
ROUTER_PROVIDERS,
110108
provide(LocationStrategy, {useClass: HashLocationStrategy}),
111109
HTTP_PROVIDERS,
110+
customProviders
112111
];
113112
}
114113

0 commit comments

Comments
 (0)