【问题标题】:Ionic2 error Property 'openDatabase' does not exist on type 'Window'Ionic2 错误“窗口”类型上不存在属性“openDatabase”
【发布时间】:2018-10-01 22:24:34
【问题描述】:

我正在尝试为 ionic2/3 创建一个备用数据库,使其成为 websql,但我被卡住了

private db:any;
constructor(
    private storage: SQLite,
    private platform: Platform,
    private windowserv:WindowServiceProvider
) {
    if (this.platform.is('core') || this.platform.is('mobileweb')) {
        this.db=window.openDatabase(this.db_name, "1.0", "Database", 2 * 1024 * 1024);
    }
}


 openSqliteDb(): Promise<any> { //returns the db object
    return new Promise<any>((resolve, reject) => {
        if (this.platform.is('core') || this.platform.is('mobileweb')) {
            try {
                resolve(this.db);
            } catch (e) {
                reject(e);
            }
        } else {
            this.storage = new SQLite();
            this.storage.create({
                name: this.db_name,
                location: this.db_location
            }).then((db: SQLiteObject) => {
                resolve(db);
            }, (error) => {
                reject(error);
            });
        }
    })

}

但现在总是报错

Property 'openDatabase' does not exist on type 'Window'.

我已经尝试添加一个窗口服务并且引导就像

@Injectable()
export class WindowServiceProvider {
  public window = window;

}

然后在应用模块上

    bootstrap: [IonicApp,[WindowServiceProvider]],

然后将其用作

windowservice.window.openDatabase ....

但即使这样也行不通。 使用网络测试时如何使用开放数据库进行离子 websql 回退

【问题讨论】:

  • 您是在浏览器还是设备上尝试过?
  • 在我的浏览器 chrome 上
  • 那行不通。 window.openDatabase 是一个 cordova 方法 & Cordova 在浏览器中不可用。

标签: javascript cordova ionic-framework ionic2 ionic3


【解决方案1】:

window.openDatabase 是一种科尔多瓦方法。所以它在浏览器中不起作用。 运行以下命令使cordova可用

$ ionic run browser

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-21
    • 2019-10-12
    • 2019-09-30
    • 2016-12-12
    • 2019-02-01
    • 2019-08-23
    • 1970-01-01
    • 2017-04-01
    相关资源
    最近更新 更多