3

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

1
  • Can you follow steps on this link and link and see what happens? Commented Apr 4, 2017 at 20:27

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

elegant answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.