我试图创建一个Ionic 4应用程序,并使用SQLite作为存储。 我已经安装了以下软件包:
ionic cordova plugin add cordova-sqlite-storage
npm install --save @ionic-native/sqlite
ionic cordova plugin add uk.co.workingedge.cordova.plugin.sqliteporter
npm install --save @ionic-native/sqlite-porter
这是我的app.module:
@NgModule({
declarations: [AppComponent],
entryComponents: [],
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule,
HttpClientModule],
providers: [
StatusBar,
SplashScreen,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy, },
SQLite,
SQLitePorter,
DatabaseService
],
bootstrap: [AppComponent]
})
这是我的DatabaseService的代码抛出错误的部分,它在.create
上失败并返回undefined:
initializeDatabase(): void {
console.log("initializing db");
// Define the application SQLite database
this._SQL
.create({
name: this._DB_NAME,
location: "default"
})
.then((db: SQLiteObject) => {
// Associate the database handler object with the _DB private property
this._DB = db;
console.log("db created");
})
.catch(e => {
console.log(e);
});
}
这是我的错误:
TypeError: Cannot read property 'then' of undefined
at DatabaseService.push../src/app/services/database.service.ts.DatabaseService.initializeDatabase (database.service.ts:49)
at new DatabaseService (database.service.ts:33)
at _createClass (core.js:21263)
at _createProviderInstance (core.js:21225)
at resolveNgModuleDep (core.js:21189)
at NgModuleRef_.push../node_modules/@angular/core/fesm5/core.js.NgModuleRef_.get (core.js:21897)
at resolveDep (core.js:22268)
at createClass (core.js:22148)
at createDirectiveInstance (core.js:22019)
at createViewNodes (core.js:23245)
请帮助,我已经坚持了两天。
答案 0 :(得分:0)
如果在浏览器中对其进行测试,则会引发错误,因为Cordova
仅在移动设备上运行。您必须在移动设备或仿真器中测试应用程序
Cordova将仅在Android和Ios等移动平台上运行