简体   繁体   English

SQLite的离子返回错误

[英]SQLite for Ionic returning error

I'm using Firefox and Chrome for development. 我正在使用Firefox和Chrome进行开发。 I installed the sqlite plugin but there's always error when firing openDB command on: 我安装了sqlite插件,但是在打开openDB命令时总是出错:

firefox(TypeError: n.sqlitePlugin is undefined ng-cordova.min.js (line 9, col 19046)) firefox(TypeError:n.sqlitePlugin是未定义的ng-cordova.min.js(第9行,col 19046))

and

chrome(Uncaught TypeError: Cannot read property 'openDatabase' of undefined ng-cordova.min.js:9ng-cordova.min.js:9) chrome(未捕获的TypeError:无法读取未定义的ng-cordova.min.js:9ng-cordova.min.js:9的属性'openDatabase')

I don't know what did I do wrong. 我不知道我做错了什么。 Please help. 请帮忙。

SQlite plugin will be activated while you are running the application in mobile and it will not be available in browsers. 在手机上运行应用程序时,SQlite插件将被激活,并且在浏览器中将不可用。 Try running your app in mobile and check. 尝试在移动设备上运行您的应用并进行检查。

While in the browser check for the existence of sqlite if not present then default to webSQL , the code could be something like this , (based omn the framework u are using it would change) 在浏览器中检查sqlite是否存在(如果不存在),然后默认为webSQL,代码可能是这样的(基于您正在使用的框架,它会发生变化)

 if(window.sqlitePlugin !== undefined) {
        console.log('opening sqlite DB ');
        db = window.sqlitePlugin.openDatabase("MyDB");
    } else {
        console.log('opening Web SQL DB ');
        db = window.openDatabase("MyDB", "1.0", "Cordova Demo", 200000);
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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