Skip to content

Commit e082bd1

Browse files
committed
fix(platform): run zone after cordova deviceready
Closes #6087
1 parent f841bef commit e082bd1

File tree

3 files changed

+23
-14
lines changed

3 files changed

+23
-14
lines changed

ionic/config/bootstrap.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {provide, Provider} from 'angular2/core';
1+
import {provide, Provider, ComponentRef, NgZone} from 'angular2/core';
22
import {ROUTER_PROVIDERS, LocationStrategy, HashLocationStrategy} from 'angular2/router';
33
import {HTTP_PROVIDERS} from 'angular2/http';
44

@@ -44,9 +44,6 @@ export function ionicProviders(args: any = {}) {
4444
setupDom(window, document, config, platform, clickBlock, featureDetect);
4545
bindEvents(window, document, platform, events);
4646

47-
// prepare the ready promise to fire....when ready
48-
platform.prepareReady();
49-
5047
return [
5148
IonicApp,
5249
provide(ClickBlock, {useValue: clickBlock}),
@@ -67,6 +64,16 @@ export function ionicProviders(args: any = {}) {
6764
}
6865

6966

67+
export function postBootstrap(appRef: ComponentRef, prodMode: boolean) {
68+
appRef.injector.get(TapClick);
69+
let app: IonicApp = appRef.injector.get(IonicApp);
70+
let platform = appRef.injector.get(Platform);
71+
let zone = appRef.injector.get(NgZone);
72+
platform.prepareReady(zone);
73+
app.setProd(prodMode);
74+
}
75+
76+
7077
function setupDom(window, document, config, platform, clickBlock, featureDetect) {
7178
let bodyEle = document.body;
7279
let mode = config.get('mode');

ionic/decorators/app.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {Component, ChangeDetectionStrategy, ViewEncapsulation, enableProdMode, Type} from 'angular2/core';
22
import {bootstrap} from 'angular2/platform/browser';
3-
import {IonicApp} from '../components/app/app';
4-
import {TapClick} from '../components/tap-click/tap-click';
5-
import {ionicProviders} from '../config/bootstrap';
3+
import {ionicProviders, postBootstrap} from '../config/bootstrap';
64
import {IONIC_DIRECTIVES} from '../config/directives';
75

86
const _reflect: any = Reflect;
@@ -41,7 +39,8 @@ export interface AppMetadata {
4139
* number of arguments that act as global config variables for the app.
4240
* `@App` is similar to Angular's `@Component` in which it can accept a `template`
4341
* property that has an inline template, or a `templateUrl` property that points
44-
* to an external html template.
42+
* to an external html template. The `@App` decorator runs the Angular bootstrapping
43+
* process automatically, however you can bootstrap your app separately if you prefer.
4544
*
4645
* @usage
4746
* ```ts
@@ -94,9 +93,7 @@ export function App(args: AppMetadata = {}) {
9493
}
9594

9695
bootstrap(cls, providers).then(appRef => {
97-
appRef.injector.get(TapClick);
98-
let app: IonicApp = appRef.injector.get(IonicApp);
99-
app.setProd(args.prodMode);
96+
postBootstrap(appRef, args.prodMode);
10097
});
10198

10299
return cls;

ionic/platform/platform.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1+
import {EventEmitter, NgZone} from 'angular2/core';
2+
13
import {Config} from '../config/config';
2-
import {EventEmitter} from 'angular2/core';
34
import {getQuerystring} from '../util/util';
45
import {ready, windowDimensions, flushDimensionCache} from '../util/dom';
56

@@ -37,6 +38,7 @@ export class Platform {
3738
private _readyPromise: Promise<any>;
3839
private _readyResolve: any;
3940
private _resizeTm: any;
41+
private _zone: NgZone;
4042

4143
constructor(platforms = []) {
4244
this._platforms = platforms;
@@ -186,16 +188,19 @@ export class Platform {
186188
* @private
187189
*/
188190
triggerReady() {
189-
this._readyResolve();
191+
this._zone.run(() => {
192+
this._readyResolve();
193+
})
190194
}
191195

192196
/**
193197
* @private
194198
*/
195-
prepareReady() {
199+
prepareReady(zone: NgZone) {
196200
// this is the default prepareReady if it's not replaced by the engine
197201
// if there was no custom ready method from the engine
198202
// then use the default DOM ready
203+
this._zone = zone;
199204
ready(this.triggerReady.bind(this));
200205
}
201206

0 commit comments

Comments
 (0)