Я пытаюсь создать приложение 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
и возвращение неопределенного:
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)
Пожалуйста, помогите, я застрял на этом в течение двух дней.