我想第一次使用带有cordova框架的sqlite.正如我在教程中读到的那样,我应该像这样使用ngcordova:
var db = null;
app.controller('mainCtrl', function ($scope, $ionicSideMenuDelegate) {
$scope.toggleLeft = function () {
$ionicSideMenuDelegate.toggleLeft();
}
$scope.toggleRight = function () {
$ionicSideMenuDelegate.toggleRight();
}
})
.controller('home_ctrl', function ($scope, $cordovaSQLite) {
db = $cordovaSQLite.openDB({name: "my.db"});
//db = $window.opendb({name: "my.db"});
$cordovaSQLite.execute(db, "CREATE TABLE IF NOT EXISTS people(id integer primary key, firstname text, lastname text)")
})
;
Run Code Online (Sandbox Code Playgroud)
当我运行此代码时出现错误:
TypeError: Cannot read property 'openDatabase' of undefined
Run Code Online (Sandbox Code Playgroud)
在这样的一些文章中:如何在Ionic Framework中使用ngCordova sqlite服务和Cordova-SQLitePlugin?
建议使用这样的命令:ionic start myApp sidemenu
我不知道它是什么,我只是使用cordova命令:cordova run android或者cordova create my_project
我应该怎么做才能从我的cordova项目中创建一个表?
Nic*_*boy 49
您可以查看本教程:
https://www.thepolyglotdeveloper.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/
当您看到此错误时:
TypeError: Cannot read property 'openDatabase' of undefined
这是因为以下几个原因之一:
$cordovaSQLite方法包装在$ionicPlatform.ready()函数中.导致此错误的最常见原因是#1和#2.本机插件必须在应用程序确认就绪后才能使用,因此该$ionicPlatform.ready()方法.由于本机插件使用本机代码,因此无法通过Web浏览器对其进行测试.
阅读我链接的教程,因为它可以帮助您.
问候,
| 归档时间: |
|
| 查看次数: |
25277 次 |
| 最近记录: |