简体   繁体   中英

Ionic2 error Property 'openDatabase' does not exist on type 'Window'

I'm trying to create a fallback database for ionic2/3 to be websql but I am stuck

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);
            });
        }
    })

}

But now am always getting an error

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

I have tried adding a window service and bootstrapping is like

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

}

then on appmodule

    bootstrap: [IonicApp,[WindowServiceProvider]],

Then using it as

windowservice.window.openDatabase ....

But even this does not work. How do I use open database for ionic websql fallback when testing with the web

window.openDatabase is a cordova method. So it wouldn't work in the browser. Run the following command to make cordova available

$ ionic run browser

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM