加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

sqlite – TypeError:无法读取未定义的属性“openDatabase”

发布时间:2020-12-12 19:04:48 所属栏目:百科 来源:网络整理
导读:我想第一次与cordova框架一起使用sqlite.正如我在教程中阅读的,我应该使用ngcordova: var db = null;app.controller('mainCtrl',function ($scope,$ionicSideMenuDelegate) { $scope.toggleLeft = function () { $ionicSideMenuDelegate.toggleLeft(); } $s
我想第一次与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',$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)")
})
;

当我运行这个代码一个错误说:

TypeError: Cannot read property 'openDatabase' of undefined

在一些这样的文章:How do I use the ngCordova sqlite service and the Cordova-SQLitePlugin with Ionic Framework?
建议使用如下命令:ion start myApp sidemenu
我不知道是什么,我只是使用cordova命令,如:cordova运行android或cordova创建my_project
我该怎么办才能运行我的cordova项目创建一个表?

你可以看看这个教程:

https://www.thepolyglotdeveloper.com/2014/11/use-sqlite-instead-local-storage-ionic-framework/

当你看到这个错误:

TypeError:无法读取未定义的属性“openDatabase”

这是发生的原因之一:

>你没有在$ionPlatform.ready()函数中包装$cordovaSQLite方法.
>您正在尝试从Web浏览器测试此本机插件.
>您没有将基本SQLite插件实际安装到项目中.

这个错误最常见的原因是#1和#2.本地插件,只有在应用程序确认后才能使用,因此$ionPlatform.ready()方法.由于本地插件使用本机代码,因此无法从Web浏览器中测试.

阅读我链接的教程,因为它应该帮助你.

问候,

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读