angular - ionic 2中的预填充数据库

标签 angular sqlite ionic2 cordova-plugins

我有一些静态数据,我已经使用 SQLite 数据库浏览器 创建了一个 SQLite 数据库文件。现在想在我的 Ionic 2 应用程序中使用该 SQLite 数据库文件。

我调查了 https://forum.ionicframework.com/t/read-existing-sqlite-database-file-and-load-data/94167/10发帖但没有得到解决方案。

谁能帮帮我!!!

ionic 信息:

@ionic/cli-utils  : 1.9.2
ionic (Ionic CLI) : 3.9.2

全局包:

Cordova CLI : 7.0.1

本地包:

@ionic/app-scripts : 2.0.2
Cordova Platforms  : none
Ionic Framework    : ionic-angular 3.5.3

最佳答案

您可以使用

cordova-sqlite-ext

用于安装,

cordova 插件添加 cordova-sqlite-ext --save

A Cordova/PhoneGap plugin to open and use sqlite databases on Android/iOS/Windows with REGEXP (Android/iOS) and pre-populated databases (Android/iOS/Windows)

var db = null;
document.addEventListener('deviceready', function() {
  db = window.sqlitePlugin.openDatabase({name: 'demo.db', location: 'default'});
});

重要:与其他 Cordova 插件一样,您的应用程序必须等待 deviceready 事件。这在 Angular/ngCordova/Ionic controller/factory/service 回调中尤其棘手,它们可能在 deviceready 事件被触发之前触发。

这里有一个详细的例子。

Ionic Framework App With Pre-Filled SQLite DB

关于angular - ionic 2中的预填充数据库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45854856/

相关文章:

Angular:在构造函数中注入(inject)路由器给出错误

javascript - 使用 Javascript 访问 JSON 对象中数组中的对象

ruby-on-rails - 在模型上编写 postgresql 方法以按星期几获取日期时间条目

sqlite - 使用executeSql进行多重插入

node.js - 安装ionic 2错误: npm ERROR cannot read property 'path' of null with windows 10

javascript - 带参数的自定义验证

javascript - visual studio typescript 与angular 2冲突

javascript - 如何在 Angular 6 中使用新的 RXJS 6 管道/映射返回解析数据?

angular - 模块 '[object Object]' 导入的意外值 'AppModule'

sql - 哪种是使用 SQLite DB 的最佳方式?