I'm trying to use SQLite on an Ionic 2 project
ionic start App_One blank --v2 --ts
Then I install the platform:
ionic platform add android
ionic platform add ios
Then SQLite plugin:
ionic plugin add cordova-sqlite-storage --save
But when I try to initialize my provider as follows:
ionic g provider db-service
Then
import { Injectable } from '@angular/core';
import { SQLite } from 'ionic-native';
@Injectable()
export class DbService {
db: SQLite = null;
constructor() {
console.log('Hello DbService Provider');
this.db = new SQLite();
}
}
I have the following error: "Cannot find name 'SQLite'"
I have try:
npm install
ionic state restore
Any idea?
Thx
Info:
Cordova CLI: 6.5.0
Ionic Framework Version: 2.3.0
Ionic CLI Version: 2.2.1
Ionic App Lib Version: 2.2.0
Ionic App Scripts Version: 1.1.4
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v7.8.0
Xcode version: Not installed
I stopped giving problems installing and changing the following fragment:
Dependency:
sudo npm install --save @ionic-native/core@latest
sudo npm install --save @ionic-native/sqlite
ionic plugin add cordova-sqlite-storage --save
sudo npm install --save @ionic/storage
Fragment:
import {SQLite} from '@ionic-native/sqlite';
@Injectable()
export class DBService {
db = null;
constructor () {
this.db = new SQLite ();
}
...
}
The fragment is initialize db in null and let the constructor take care of instantiating SQLite.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With