SQLite 不适用于 Ionic 2

SQLite not working on Ionic 2

无法在我的 Angular 2/Ionic 2 项目中使用 SQLite 插件。

根据 Ionic 2 文档实例化 SQLite 的方式无效。

Sublime 给我一个错误信息:

Supplied parameters do not match nay signature of the call target.

意思是构造函数应该接收参数。但是什么参数?

Ionic 2 SQLite 插件文档: http://ionicframework.com/docs/v2/native/sqlite/

import { SQLite } from 'ionic-native';

let db = new SQLite();
db.openDatabse({
  name: 'data.db',
  location: 'default' // the location field is required
}).then(() => {
  db.executeSql('create table danceMoves(name VARCHAR(32))', {}).then(() => {

  }, (err) => {
    console.error('Unable to execute sql', err);
  })
}, (err) => {
  console.error('Unable to open database', err);
});

它还说 属性 'openDatabse' 在类型 'SQLite'

上不存在

通过从头开始重新创建项目并处理旧的应用程序文件夹、配置并重新安装 npm 模块和 ionic 本机插件来解决。

db.openDatabase,不是数据bse

但我认为现在是 .create 而不是 .openDatabase。

当你说 .then(() => {db.executeSql ... 尝试添加 .then((db: SQLiteObject) 并且接下来: {}).then(() => {}, (err) => {( )[= 之间添加数据14=]

可能会尝试使用

导入 SQLite 对象
import { SQLite, SQLiteObject } from '@ionic-native/sqlite';

注意:不要忘记安装 ionic-native/sqlite

npm install --save @ionic-native/sqlite

我按照以下步骤解决了这个问题。

添加并安装插件

ionic cordova plugin add cordova-sqlite-storage

npm install --save @ionic-native/sqlite

现在创建一个数据库。

let db = new SQLite();
            db.openDatabase({
                name: "data.db",
                location: "default"
            }).then(() => {
});

如果您收到如下错误:"openDatabse does not exist on type 'SQLite"。只需删除 node_module 文件夹并重新安装 node_module。

它会起作用。