无法打开数据库cordova_not_available

时间:2017-07-12 11:39:53

标签: sqlite typescript ionic2

我在ionic2中使用Sqlite进行编码,但我接受此错误“无法打开数据库cordova_not_available”。怎么能解决这个问题

Thanx寻求帮助。

我的错误(无法打开数据库cordova_not_available)

我的代码;

import { Component } from '@angular/core';
import { Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';
import { TabsPage } from '../pages/tabs/tabs';

@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  rootPage:any = TabsPage;

  constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen) {



    platform.ready().then(() => {
      statusBar.styleDefault();
      splashScreen.hide();


       let db = new SQLite();
       db.create({
                name: "iothook.db",
                location: "default"
            }).then((db1:SQLiteObject) => {
                db1.executeSql("CREATE TABLE IF NOT EXISTS kullanici (id INTEGER PRIMARY KEY AUTOINCREMENT, username TEXT, password TEXT , token TEXT , user_id INTEGER)", {}).then((data) => {
                    console.log("TABLE CREATED: ", data);
                }, (error) => {
                    console.error("Unable to execute sql", error);
                })
            }, (error) => {
                console.error("Unable to open database", error);
            });

    });
  }
}

1 个答案:

答案 0 :(得分:5)

Cordova功能仅适用于移动设备。浏览器不支持它们。