【发布时间】: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