我试图为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;
}
然后在appmodule上
bootstrap: [IonicApp,[WindowServiceProvider]],
然后将其用作
windowservice.window.openDatabase ....
但即使这样也行不通。 在使用Web进行测试时,如何使用open database for ionic websql fallback
答案 0 :(得分:1)
window.openDatabase
是一种科尔多瓦方法。所以它在浏览器中不起作用。
运行以下命令以使cordova可用
$ ionic run browser