我想将 SQLite 数据添加到我的 ionic 移动应用程序中,我已按照以下站点中的教程一步步操作 https://blog.nraboy.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/但它仍然无法在物理设备上运行,有什么建议吗? 在index.html中我放置了以下代码 `
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="lib/ionic/js/angular-ui/angular-ui-router.js"></script>
<script src="lib/ionic/js/angular/angular-resource.js"></script>
<!-- Needed for Cordova/PhoneGap (will be a 404 during development) -->
<script src="js/app.js"></script>
<script src="js/ng-cordova.min.js"></script>
<script src="cordova.js"></script>`
在我的 app.js 中,我首先编写了以下代码
var db=null;
var myApp=angular.module('myApp',['ionic','ngCordova'])
.run(function($ionicPlatform, $cordovaSQLite) {
$ionicPlatform.ready(function() {
if(window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if(window.StatusBar) {
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB("test.db");
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people (id integer primary key, firstname text, lastname text)");
console.log("hello");
})
})
所以我创建了一个名为 people 的表,并在我的登录 Controller 中向 people 表插入一行
controller('loginController',function($scope,$cordovaSQLite){
var query = "INSERT INTO people (id,firstname, lastname) VALUES (?,?,?)";
$cordovaSQLite.execute(db, query, [1,"khaled", "omar"]).then(function(res) {
$scope.name=res.insertId;
}, function (err) {
$scope.name="error";
});
在login.html中我写了{{name}},但是当我在浏览器上运行它时,我收到以下错误无法读取未定义的属性“openDatabase”,我在物理设备上运行它但仍然不起作用
最佳答案
代码运行良好,看来错误来自 Controller 中的问题。
关于cordova - ionic cordovaSQLite 插件无法在物理设备上运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27616609/