Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
android上运行的ionic 2 sqlite:无法读取未定义的属性executeSql_Sqlite_Angular_Plugins_Ionic2 - Fatal编程技术网

android上运行的ionic 2 sqlite:无法读取未定义的属性executeSql

android上运行的ionic 2 sqlite:无法读取未定义的属性executeSql,sqlite,angular,plugins,ionic2,Sqlite,Angular,Plugins,Ionic2,我写了一个测试标签离子2应用程序使用sqlite插件。我将sqlite包装为Provider: import { SQLite, Device } from 'ionic-native'; import { Injectable } from '@angular/core'; import { Http } from '@angular/http'; import 'rxjs/add/operator/map'; /* Generated class for the SqliteHelpe

我写了一个测试标签离子2应用程序使用sqlite插件。我将sqlite包装为Provider:

import { SQLite, Device } from 'ionic-native';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

/*
  Generated class for the SqliteHelper provider.

  See https://angular.io/docs/ts/latest/guide/dependency-injection.html
  for more info on providers and Angular 2 DI.
*/
@Injectable()
export class SqliteHelper {

  public db : SQLite;
  public log : string = "";
  constructor(public http: Http) {
    console.log('Hello SqliteHelper Provider');
  }

  public initDb() {
    this.db = new SQLite();
    this.log += "openDatabase。。。";
    // if (Device.device.platform)
    this.db.openDatabase({
      name: "data.db",
      location: "default"
    }).then((data) =>{
      this.log += ("open ok " + JSON.stringify(data));
    }, (err) => {
      this.log += ("open err " + err.message + " " + JSON.stringify(err));
    });
  }

  public executeSql(statement: string, parms:any) {
    return this.db.executeSql(statement, parms);
  }

}
和app.components中的init sqlitehelper:

  constructor(platform: Platform, sqliteHelper : SqliteHelper, events: Events) {
    platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      sqliteHelper.initDb();
      events.publish("sqlite:inited", null);
      StatusBar.styleDefault();
      Splashscreen.hide();
    });
  }
我从带有platform.ready的构造函数的第一个tabs页面加载数据,在android上运行它将导致错误:无法读取未定义的属性executeSql


如果我通过点击按钮加载数据,就可以了。或者我将loaddata放入第二页的构造函数,也没关系。为什么?谁能帮助我,我想将代码放入第一页,并在页面开始时加载数据。

我在尝试插入数据库时遇到了相同的错误,因此我在事务中添加了“executeSql”函数:

     this.database.openDatabase({
                        name: "sis.db",
                        location: "default"
                    }).then(() => {

this.database.executeSql("CREATE TABLE IF NOT EXISTS profile(id integer primary key autoincrement NOT NULL ,name Text NOT NULL)", []).then((data) => { console.log('profile table created'); }, (error) => { console.log('Unable to create table profile'); })

this.database.transaction(tr => { tr.executeSql("insert into profile(id,name) values(12,'Ibrahim')", []); }).then(d => { console.log('Data inserted ya hima'); }, err => { console.error('unable to insert data into profile table'); });
                        this.database.executeSql("select id from profile", []).then(d => { console.log('inserted id=' + d.rows.item(0).app_id); }, err => { console.error('unable to get ID from profile table'); });

                        }, (error) => {console.error(error); }
                        );