sqlitePlugin is not defined

Hi friends,

I am trying to store some data in the sqlite stroage in my new ionic 2 application. but when i try to call the function to store the information in th db it says sqlite plugin not defined.

the code to create the table is

public createUserTable(){
new SQLite().openDatabase({
name:SQLService.db,
location:‘default’
})
.then((db: SQLite) => {
console.log(JSON.stringify(db));
db.executeSql(“CREATE TABLE IF NOT EXISTS users (id INTEGER PRIMARY KEY AUTOINCREMENT, username varchar(100), token varchar(100), branchOfficeId int, password varchar(100)”,{}).then(() => {}).catch(() => {});

    }, (err) => {
        console.error('Unable to execute sql: ' + err);
    }); 
}

i have also make sure that it is called on platform ready

platform.ready().then(() => {
StatusBar.styleDefault();
Splashscreen.hide();
sqlService.createUserTable();
});

but the error persists

Thanks,
Ajay

Hi there .
Where are you testing your app ?
are you using ionic serve ?
if so , cordova plugins don’t work in ionic serve
try building and running on an actual device or emulator:
add a platform : ionic platform add android
build and run app : ionic run android

yes i had tried both but the problem is still there

Did you add the plugin to your project correctly , try ionic plugin list and see if it’s there ,
also did you import it in your service .

this is the response i get when i run the command

© 2016 Microsoft Corporation. All rights reserved.

C:\Users\Ajay\Desktop\ionic\Miodoc2>ionic plugin list
cordova-plugin-console 1.0.4 "Console"
cordova-plugin-device 1.1.3 "Device"
cordova-plugin-splashscreen 4.0.0 "Splashscreen"
cordova-plugin-statusbar 2.2.0 "StatusBar"
cordova-plugin-whitelist 1.3.0 "Whitelist"
cordova-sqlite-storage 2.0.0 "Cordova sqlite storage plugin"
ionic-plugin-keyboard 2.2.1 “Keyboard”

As you can see you don’t have the plugin in your App you can add it by running ionic plugin add cordova-sqlite-storage
Also make sure to import it in your service typescript file like this import { SQLite } from 'ionic-native';
for more details see the Plugin Documentation

hi now it is having a new problem

can you help?

yes i have imported the SQLite from ionic native