2

My ionic2 app loads the main page and starts fetching the data using a custom DBService which in turn uses Cordova SQLite plugin, but at this time the platform is not ready and thus sqlitePlugin is not available.

How do I stop application to bootstrap until the platform is ready (and SQlite db is open)?

I found a solution for angular1 based apps where bootstraping is delayed until 'deviceready' event is fired.

Can anybody suggest a solution for ionic2 based apps?

Community
  • 1
  • 1
Aditya Jain
  • 1,077
  • 1
  • 12
  • 25

2 Answers2

0
import { Platform } from 'ionic-angular';

export class MyApp {
  constructor(platform: Platform ) {
    platform.ready().then(() => {
      // Add your method here.
    });
  }
}
raj
  • 5,989
  • 7
  • 30
  • 62
0

There's an issue for this case on GitHub:

https://github.com/driftyco/ionic2-app-base/issues/114

Adjust your main.ts like this:

import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
import { AppModule } from './app.module';

function bootstrap() {
  platformBrowserDynamic().bootstrapModule(AppModule);
}

if (window['cordova']) {
  document.addEventListener('deviceready', () => bootstrap());
} else {
  bootstrap();
}
kaynow
  • 27
  • 6
  • I know, the issue was created based on this question itself. :) https://forum.ionicframework.com/t/bootstrap-ionic-2-after-platform-ready/73163 – Aditya Jain Jan 31 '17 at 18:56