我正在尝试使用离子框架与Sqllite。这是我的app.js代码
var db = null;
angular.module('starter', ['ionic', 'starter.controllers','ngCordova'])
.run(function($ionicPlatform,$cordovaSQLite) {
$ionicPlatform.ready(function() {
// Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
// for form inputs)
if (window.cordova && window.cordova.plugins.Keyboard) {
cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
}
if (window.StatusBar) {
// org.apache.cordova.statusbar required
StatusBar.styleDefault();
}
db = $cordovaSQLite.openDB({ name: "my.db" });
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people(id interger primary key , firstname text, lastname text)");
});
})
我的index.html代码在这里
<script src="lib/ionic/js/ionic.bundle.js"></script>
<script src="js/ng-cordova.min.js"></script>
<!-- cordova script (this will be a 404 during development) -->
<script src="cordova.js"></script>
当我运行以下命令时
离子服务
它打开了 的 http://localhost:8100/#/login
现在我有两个问题
1)它给了我错误
TypeError:n.sqlitePlugin未定义
2)创建my.db的位置。我可以实际查看吗
由于
答案 0 :(得分:0)
您需要为设备和浏览器分配代码。 这项工作对我和其他人来说:
if (window.cordova) {
//device
db = $cordovaSQLite.openDB({ name: "my.db" });
}else{
// browser
db = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100);
}