Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 无法打开数据库引用错误:未定义sqlitePlugin_Ios_Sqlite_Angular_Ionic2 - Fatal编程技术网

Ios 无法打开数据库引用错误:未定义sqlitePlugin

Ios 无法打开数据库引用错误:未定义sqlitePlugin,ios,sqlite,angular,ionic2,Ios,Sqlite,Angular,Ionic2,我正在Angular2和Ionic2中开发ios应用程序 我的系统信息是: 我的Product.ts文件代码是: import { Component} from '@angular/core'; import {NavController, NavParams, Modal} from 'ionic-angular'; import {Platform, ionicBootstrap} from 'ionic-angular'; import {StatusBar, SQLite} from

我正在Angular2和Ionic2中开发ios应用程序

我的系统信息是:

我的Product.ts文件代码是:

import { Component} from '@angular/core';
import {NavController, NavParams, Modal} from 'ionic-angular';
import {Platform, ionicBootstrap} from 'ionic-angular';
import {StatusBar, SQLite} from 'ionic-native';

@Component({
  templateUrl: 'build/pages/product/product.html',
})

export class ProductPage {
  public database: SQLite;
  public peoples: Array<Object>;

  constructor(public platform: Platform)
   {
    //this.createSqliteDB();
    //this.openDB();
    //this.addDB();
    //this.refreshDB();
    //this.showDBValue();
  }

  createSqliteDB()
  {
    console.log("createSqliteDB called.");

    let db = new SQLite();
    db.openDatabase({
        name: "data.db",
        location: "default"
        }).then(() => {
          db.executeSql("CREATE TABLE IF NOT EXISTS people (id INTEGER PRIMARY KEY AUTOINCREMENT, firstname TEXT, lastname TEXT)", {}).then((data) => {
          console.log("TABLE CREATED: ", data);
          }, (error) => {
            console.error("Unable to execute sql", error);
          })
          }, (error) => {
            console.error("Unable to open database", error);
      });



    }

  openDB()
  {
    console.log("openDB called.");

    this.database = new SQLite();
    this.database.openDatabase({name: "data.db", location: "default"}).then(() => {
      this.refreshDB();
    }, (error) => {
      console.log("openDB ERROR: ", error);
    });
  }

  public addDB() 
  {
    console.log("addDB called.");

    this.database.executeSql("INSERT INTO people (firstname, lastname) VALUES ('Nic', 'Raboy')", []).then((data) => {
            console.log("INSERTED: " + JSON.stringify(data));
        }, (error) => {
            console.log("addDB ERROR: " + JSON.stringify(error.err));
        });
    }

  public refreshDB() 
  {
    console.log("refreshDB called.");

    this.database.executeSql("SELECT * FROM people", []).then((data) => {
            this.people = [];
            if(data.rows.length > 0) {
                for(var i = 0; i < data.rows.length; i++) {
                    this.people.push({firstname: data.rows.item(i).firstname, lastname: data.rows.item(i).lastname});
                }
            }
        }, (error) => {
            console.log("refreshDB ERROR: " + JSON.stringify(error));
        });
  }

  showDBValue()
  {
    console.log("showDBValue called.");

    this.database = new SQLite();
        this.database.openDatabase({name: "data.db", location: "default"}).then(() => {
            this.refreshDB();
        }, (error) => {
            console.log("ERROR: ", error);
        });
  }

  getData()
  {
    console.log("getData called.");

    //this.database = new SQLite();
    //console.log("this.database obj: ",this.database);

    this.createSqliteDB();
    //this.openDB();
    //this.addDB();
    //this.refreshDB();
    //this.showDBValue();
  }
}
从'@angular/core'导入{Component};
从“离子角度”导入{NavController,NavParams,Modal};
从“离子角度”导入{Platform,ionicBootstrap};
从“ionic native”导入{StatusBar,SQLite};
@组成部分({
templateUrl:'build/pages/product/product.html',
})
导出类ProductPage{
公共数据库:SQLite;
公众:阵列;
建造商(公共平台:平台)
{
//这是createSqliteDB();
//这是openDB();
//这是addDB();
//这是refreshDB();
//this.showDBValue();
}
createSqliteDB()
{
log(“createSqliteDB调用”);
设db=newsqlite();
db.openDatabase({
名称:“data.db”,
位置:“默认”
}).然后(()=>{
db.executeSql(“如果不存在创建表人员(id整数主键自动递增,firstname文本,lastname文本)”,{})。然后((数据)=>{
日志(“创建的表:”,数据);
},(错误)=>{
console.error(“无法执行sql”,错误);
})
},(错误)=>{
控制台错误(“无法打开数据库”,错误);
});
}
openDB()
{
log(“调用openDB”);
this.database=new SQLite();
this.database.openDatabase({name:“data.db”,location:“default”})。然后(()=>{
这是refreshDB();
},(错误)=>{
log(“openDB错误:”,错误);
});
}
公共addDB()
{
log(“addDB调用”);
this.database.executeSql(“插入到人(firstname,lastname)值('Nic','Raboy'),[])。然后((data)=>{
log(“插入:+JSON.stringify(数据));
},(错误)=>{
log(“addDB ERROR:+JSON.stringify(ERROR.err));
});
}
公共刷新数据库()
{
log(“调用refreshDB”);
this.database.executeSql(“从人中选择*,[])。然后((数据)=>{
this.people=[];
如果(data.rows.length>0){
对于(var i=0;i{
log(“refreshDB错误:+JSON.stringify(错误));
});
}
showDBValue()
{
log(“showDBValue被调用”);
this.database=new SQLite();
this.database.openDatabase({name:“data.db”,location:“default”})。然后(()=>{
这是refreshDB();
},(错误)=>{
日志(“错误:”,错误);
});
}
getData()
{
log(“getData调用”);
//this.database=new SQLite();
//log(“this.database obj:”,this.database);
这是createSqliteDB();
//这是openDB();
//这是addDB();
//这是refreshDB();
//this.showDBValue();
}
}
我已在应用程序中使用SQLite数据库进行本地存储,并运行应用程序以显示此错误:

共享您的product.ts代码,您在其中遇到错误。@ranakrunal9我已经添加了我的product.ts文件代码。您解决了这个问题吗?没有@logic unit,我没有解决这个问题:(