Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.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
获取ionic3项目中的类型“SQLite”上不存在错误属性“openDatabase”?_Sqlite_Ionic Framework_Ionic2_Ionic3 - Fatal编程技术网

获取ionic3项目中的类型“SQLite”上不存在错误属性“openDatabase”?

获取ionic3项目中的类型“SQLite”上不存在错误属性“openDatabase”?,sqlite,ionic-framework,ionic2,ionic3,Sqlite,Ionic Framework,Ionic2,Ionic3,我的错误: 承诺中未捕获的运行时错误:TypeError: _this.sqlstorage.openDatabase不是函数类型错误:\ this.sqlstorage.openDatabase不是位于t.invoke的函数 在Object.onInvoke 在t.invoke 在r.run 在 在t.invokeTask 在 Object.onInvokeTask位于 t、 调用任务 r、 运行任务 堆叠 错误:未捕获承诺:TypeError:\u this.sqlstorage.openD

我的错误:

承诺中未捕获的运行时错误:TypeError: _this.sqlstorage.openDatabase不是函数类型错误:\ this.sqlstorage.openDatabase不是位于t.invoke的函数 在Object.onInvoke 在t.invoke 在r.run 在 在t.invokeTask 在 Object.onInvokeTask位于 t、 调用任务 r、 运行任务

堆叠

错误:未捕获承诺:TypeError:\u this.sqlstorage.openDatabase 不是函数类型错误:\ this.sqlstorage.openDatabase不是 作用 在 在t.invoke 在Object.onInvoke 在t.invoke 在r.run 在 在t.invokeTask 在Object.onInvokeTask 在t.invokeTask 在r.runTask 在c 在 在t.invokeTask 在Object.onInvokeTask 在t.invokeTask 在r.runTask 在 在HTMLDocument.invoke

My Home.ts文件:

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

@Component({
  selector: 'page-home',
  templateUrl: 'home.html'
})
export class HomePage {
    sqlstorage: SQLite;
    items: Array<Object>;

  constructor(public navCtrl: NavController, private platform: Platform) {
     this.platform.ready().then(() => {
            for (var i = 100000 - 1; i >= 0; i--) {
                console.log("test");
                    }
            this.sqlstorage = new SQLite();
            this.sqlstorage.openDatabase({name: "items.db", location: "default"}).then(() => {
                this.createTables();
                this.findAll();
            }, (err) => {
                console.log("!!! ", err);
            });
        });

  }

  public createTables(){
        this.sqlstorage.executeSql(`create table if not exists items(
            reference CHAR(10) PRIMARY KEY,
            name CHAR(30),
            qMin FLOAT,
            qReal FLOAT
        ))`, {});            
    }}
但是没有帮助。

您应该将SQLite注入到构造函数中。SQLite似乎没有一个叫做openDatabase的函数。声明使用函数createconfig:SQLiteDatabaseConfig创建或打开数据库

...

private db: SQLiteObject;

constructor(private sqlite: SQLite, private platform: Platform) {
    platform.ready().then(() => {
        sqlite.create({
            name: "items.db",
            location: "default"
        })
        .then(db => {
            this.db = db;
            this.createTables();
        }
    });
}

createTables(){
    this.db.executeSql(...);
}

...

找到解决方案了吗?这是否意味着将使用.thendb=>{this.db=db;this.createTables;}加载当前数据库?
...

private db: SQLiteObject;

constructor(private sqlite: SQLite, private platform: Platform) {
    platform.ready().then(() => {
        sqlite.create({
            name: "items.db",
            location: "default"
        })
        .then(db => {
            this.db = db;
            this.createTables();
        }
    });
}

createTables(){
    this.db.executeSql(...);
}

...
/* This is sqlite object */
  public database: SQLiteObject;

/* This will notify when platform is ready and database is ready to trasction */
private databaseReady: BehaviorSubject<boolean>;

private options = { name: 'test.db', location: 'default' };

this.databaseReady = new BehaviorSubject(false);
    this.platform.ready().then(() => {
      console.log(this.TAG, 'platform is ready');
      this.sqlite.create(this.options)
      .then((db: SQLiteObject) => {
       this.database = db;
       console.log(this.TAG, this.database);
       this.databaseReady.next(true);
       db.executeSql('select tbl_name from sqlite_master', []).then(data => {
         console.log(this.TAG, data);
         }).catch(e => console.log(e));
      });
    }).catch(e => console.log(e));
   }
  public getDatabaseState() {
    return this.databaseReady.asObservable();
  }

//On your page ts file

this.database.getDatabaseState().subscribe(result => {
      console.log(this.TAG, 'Database State', result);
        if (result) {

        }
});