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