gpt4 book ai didi

android - 在 ionic 2 中使用 SQLite 时出现 sqlitePlugin 错误

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:55:00 25 4
gpt4 key购买 nike

I'm trying to implement this simple example given in ionic 2 doc: http://ionicframework.com/docs/v2/native/sqlite/

我在 MAC 上尝试了这个例子(在 ionic 项目的 'www\test.sqlite' 文件夹下的数据库上执行查询),我都得到了这个错误在浏览器和 iOS 模拟器上(也不适用于设备):

ReferenceError: sqlitePlugin 未定义

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

代码:

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);
});
}

}

ionic details: Cordova CLI: 6.4.0 Ionic Framework Version: 2.0.0-rc.3 Ionic CLI Version: 2.1.17 Ionic App Lib Version: 2.1.7 Ionic App Scripts Version: 0.0.45 ios-deploy version: Not installed ios-sim version: Not installed OS: OS X El Capitan Node Version: v7.2.1 Xcode version: Xcode 8.1 Build version 8B62

最佳答案

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

ionViewDidLoad(){
this.platform.ready().then((readySource) => {
this.pps.getSummary(); //pps is a provider named ProdPerfService
});
}

关于android - 在 ionic 2 中使用 SQLite 时出现 sqlitePlugin 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41330841/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com