简体   繁体   English

平台准备好后,Ionic 2引导程序

[英]Ionic 2 bootstrap after platform ready

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. 我的ionic2应用程序加载了主页,并开始使用自定义DBService来获取数据,而后者又使用了Cordova SQLite插件,但是此时平台尚未准备就绪,因此sqlitePlugin不可用。

How do I stop application to bootstrap until the platform is ready (and SQlite db is open)? 如何停止应用程序进行引导,直到平台准备就绪(并且SQlite数据库已打开)?

I found a solution for angular1 based apps where bootstraping is delayed until 'deviceready' event is fired. 我发现了一个基于angular1的应用程序的解决方案 ,其中引导程序被延迟到触发“ deviceready”事件为止。

Can anybody suggest a solution for ionic2 based apps? 有人可以为基于ionic2的应用程序提出解决方案吗?

import { Platform } from 'ionic-angular';

export class MyApp {
  constructor(platform: Platform ) {
    platform.ready().then(() => {
      // Add your method here.
    });
  }
}

There's an issue for this case on GitHub: GitHub上的这种情况有一个问题:

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

Adjust your main.ts like this: 像这样调整main.ts

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();
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM