Ionic 2: Cannot find the name "SQLite"

I am trying to use SQLite in 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 the SQLite plugin:

ionic plugin add cordova-sqlite-storage --save

      

But when I try to initialize my provider like this:

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 the SQLite name"

I tried:

npm install
ionic state restore

      

Any idea?

thank

information:

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

+3


source to share


1 answer


I stopped asking problems when installing and modifying the following snippet:

Dependence:

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 initializes the db to zero and allows the constructor to take care of creating the SQLite instance.

+2


source







All Articles