brodycj / cordova-sqlite-ext

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/macOS/Windows with REGEXP (Android/macOS/iOS) and pre-populated databases (Android/iOS/macOS/Windows)
Other
72 stars 55 forks source link

Cannot find name 'SQLite' / 'SQLiteObject' with Ionic 2 #59

Closed alexhmm closed 7 years ago

alexhmm commented 7 years ago

hey,

I wanted to setup a fresh new blank project with a pre-populated database using the code from: https://github.com/iursevla/ionic2-PreDB

But i do get these errors and don't know what i can do:

home.ts:

`import { Component } from '@angular/core'; import { NavController, Platform } from 'ionic-angular'; import { SQLite, SQLiteObject } from "@ionic-native/sqlite";

@Component({ selector: 'page-home', templateUrl: 'home.html' }) export class HomePage {

private options = { name: "data.db", location: 'default', createFromLocation: 1 };
private queryNames = "SELECT * FROM testTable";
public names: String[] = [];

searchQuery: string = '';
items: string[];

constructor(public navCtrl: NavController, private sqlite: SQLite, private platform: Platform) { this.initializeItems();

}

ionViewDidLoad() { //Once the main view loads //and after the platform is ready... this.platform.ready().then(() => { console.log("PLATFORM READY"); this.sqlite.create(this.options).then((db: SQLiteObject) => {
console.log("CREATE OK"); db.executeSql(this.queryNames, {}).then((data) => {
let rows = data.rows; for (let i = 0; i < rows.length; i++) this.names.push(rows.item(i).name); console.log("Number of names on database = " + this.names.length); }) }); console.log("PLATFORM READY.");
}); }

initializeItems() {
    this.items = [
        'Amsterdam',
        'Bogota',
        'Berlin',
        'Hamburg'
    ];
}

public getNames(ev: any) {
    // Reset items back to all of the items
    this.initializeItems();

    // set val to the value of the searchbar
    let val = ev.target.value;

    // if the value is an empty string don't filter the items
    if (val && val.trim() != '') {
        this.items = this.items.filter((item) => {
            return (item.toLowerCase().indexOf(val.toLowerCase()) > -1);
        })
    }
}

} `

I installed cordova-sqlite-ext only, did imported and added SQLite to app.module.ts and also did put this line into config.xml: <plugin name="cordova-sqlite-ext" spec="~0.10.4" src="https://github.com/litehelpers/cordova-sqlite-ext" />

package.json:
"@ionic-native/sqlite": "^3.4.4",

Plz help. Thanks in advance!

Edit: With cordova-sqlite-storage plugin I have the same problem.

Greetings

Shashank-Gupta-102 commented 3 years ago

Any update on this?