sqlitePlugin在离子2中使用SQLite时出错

时间:2016-12-26 11:49:44

标签: android ios sqlite cordova angular

  

我正在尝试实现离子2 doc中给出的这个简单示例:   http://ionicframework.com/docs/v2/native/sqlite/

我在'www\test.sqlite'上尝试了这个例子(对位于MAC离子项目的constructor(public navCtrl: NavController, public platform: Platform, public pps: ProdPerfService){ platform.ready().then((readySource) => { pps.getSummary(); //pps is a provider named ProdPerfService }); } //ProdPerfService: import { Injectable } from '@angular/core'; import { SQLite } from 'ionic-native'; @Injectable() export class ProdPerfService { constructor(){ } getSummary(){ let db = new SQLite(); db.openDatabase({ name: 'test.sqlite', location: 'default' // the location field is required }).then(() => { db.executeSql('select * from summary', {}).then(() => { alert('result'); }, (err) => { console.error('Unable to execute sql: ', err); alert('err'); }) }, (err) => { console.error('Unable to open database: ', err); alert(err); }); } } 文件夹下的数据库执行查询),我在浏览器和iOS模拟器上都遇到此错误(不能正常工作)设备)):

ReferenceError:未定义sqlitePlugin

我已将cordova-sqlite-storage插件添加到离子项目中。

代码:

forEach()
  

离子细节:Cordova CLI:6.4.0离子框架版本:2.0.0-rc.3   Ionic CLI版本:2.1.17 Ionic App Lib版本:2.1.7 Ionic App   脚本版本:0.0.45 ios-deploy版本:未安装ios-sim   版本:未安装操作系统:OS X El Capitan节点版本:v7.2.1 Xcode   版本:Xcode 8.1 Build版本8B62

2 个答案:

答案 0 :(得分:0)

尝试将逻辑移出构造函数。

<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
    <ItemTemplate>
        <asp:ImageButton ID="ImageButton1" runat="server" CommandName="img" CommandArgument='<%#Eval("Mid") %>' />
    </ItemTemplate>
</asp:Repeater>

答案 1 :(得分:0)

您需要添加下一个细节:

在您的进口商品中:

getSummary(){
    let db = new SQLite();
    db.openDatabase({
        name: 'test.sqlite',
        location: 'default' // the location field is required
    }).then((sqlite: SQLiteObject) => {

在getSummary()函数中:

@Component#factory

我希望这可以解决您的问题。