IOnic 4 with SQLite data implementation. pls clarify

Dear Friends,

Iam following youtube lesson (https://www.youtube.com/watch?v=BOXZBzBwfBQ) and learning Ionic4 with SQLIte local data storing. Iam using same exactly code as below.

app.module.ts

import { NgModule } from ‘@angular/core’;
import { BrowserModule } from ‘@angular/platform-browser’;
import { RouteReuseStrategy } from ‘@angular/router’;

import { IonicModule, IonicRouteStrategy } from ‘@ionic/angular’;
import { SplashScreen } from ‘@ionic-native/splash-screen/ngx’;
import { StatusBar } from ‘@ionic-native/status-bar/ngx’;

import { AppComponent } from ‘./app.component’;
import { AppRoutingModule } from ‘./app-routing.module’;
import {SQLite} from ‘@ionic-native/sqlite/ngx’
import { from } from ‘rxjs’;

@NgModule({
declarations: [AppComponent],
entryComponents: ,
imports: [BrowserModule, IonicModule.forRoot(), AppRoutingModule],
providers: [
StatusBar,
SplashScreen,
SQLite,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
bootstrap: [AppComponent]
})
export class AppModule {}

home.page.ts

import { Component } from ‘@angular/core’;
import {SQLite, SQLiteObject} from ‘@ionic-native/sqlite/ngx’;
import { from } from ‘rxjs’;

@Component({
selector: ‘app-home’,
templateUrl: ‘home.page.html’,
styleUrls: [‘home.page.scss’],
})
export class HomePage {

constructor( public sqlite:SQLite) {
this.sqlite.create(
{
name:‘ex.db’,
location:‘default’
}
).then(
(db : SQLiteObject) => {
console.log(JSON.stringify(db))
this.addHero(db)
}
)
}

addHero(dbObj : SQLiteObject){

}

printAllHeros(dbObj : SQLiteObject){

}

}

**When i compile using ionic serve, **
it gives below error:

core.js:6014 ERROR Error: Uncaught (in promise): TypeError: Cannot read property ‘then’ of undefined
TypeError: Cannot read property ‘then’ of undefined
at new HomePage (home.page.ts:18)
at createClass (core.js:31987)
at createDirectiveInstance (core.js:31807)
at createViewNodes (core.js:44210)
at createRootView (core.js:44082)
at callWithDebugContext (core.js:45632)
at Object.debugCreateRootView [as createRootView] (core.js:44848)
at ComponentFactory_.create (core.js:30788)
at ComponentFactoryBoundToModule.create (core.js:25731)
at ViewContainerRef_.createComponent (core.js:30995)
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:39680)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)

Please help me to solve this issue. i want to create db, add and delete the data.

Please note that iam new to ionic4 with sqllite. I know html and javascript. Basicallly iam a AS# programmer.

Thanks and Regards,

Syed Abdul Rahim

A nightmare. I solved using ionic-storage You could use:
–ionic-storage
–capacitor storage api
–native storage

u mean add storage plugin in command? i did already
iam new to ionic pls explain me how to solve this isssue

Hi.

I will send you snippets of how I could do it.

I had the same error like you with sqlite, so I decided to look for another solution.

I’m working now, but I will write you again.

regards.

You must be comfortable with using Promises in typescript.

Read about that.