ionic+sqlite在浏览器中工作,但在实际设备上出现TypeError

ionic +sqlite working in browser but TypeError on real device

本文关键字:TypeError 浏览器 工作 ionic+sqlite      更新时间:2023-09-26

我仍在开发我的第一个ionic应用程序,再次遇到了一个问题:

我的应用程序使用SQLite来存储数据。我使用ngCordova的sqlite插件和litehlpers的cordova sqlite存储插件。

如果我用"离子服务实验室"测试这个应用程序,一切都很好。没有错误,数据库在那里,数据还可以…

但是,如果我去测试它在安卓设备"离子运行安卓-l-c-s"我得到以下错误,应用程序冻结:

0     779681   error    TypeError: Cannot read property 'transaction' of undefined
    at Object.execute (http://192.168.1.14:8100/lib/ngCordova/dist/ng-cordova.js:6872:11)
    at new <anonymous> (http://192.168.1.14:8100/js/controllers.js:284:18)
    at Object.instantiate (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:18010:14)
    at $controller (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:23412:28)
    at self.appendViewElement (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:59900:24)
    at Object.switcher.render (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:57893:41)
    at Object.switcher.init (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:57813:20)
    at self.render (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:59759:14)
    at self.register (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:59717:10)
    at updateView (http://192.168.1.14:8100/lib/ionic/js/ionic.bundle.js:65398:23)

我的应用程序有4个页面,可以使用ui路由器。每个页面都有自己的控制器。

两个星期以来,我一直在寻找和尝试,但没有机会。。。

有什么提示吗?

谢谢,基督教的

我发现了问题:在设备上加载数据库需要更长的时间,而且开箱即用的Ionic(->AngularJS->JavaScript)不会等待任务。

所以我不得不使用承诺:

  • http://andyshora.com/promises-angularjs-explained-as-cartoon.html
  • https://docs.angularjs.org/api/ng/service/$q

现在它工作了。。。