2
我寫了一個測試選項卡ionic 2 app使用sqlite插件。我件中的SQLite作爲provier:離子2 sqlite在android上運行:無法讀取屬性executeSql的undefined
import { SQLite, Device } from 'ionic-native';
import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';
/*
Generated class for the SqliteHelper provider.
See https://angular.io/docs/ts/latest/guide/dependency-injection.html
for more info on providers and Angular 2 DI.
*/
@Injectable()
export class SqliteHelper {
public db : SQLite;
public log : string = "";
constructor(public http: Http) {
console.log('Hello SqliteHelper Provider');
}
public initDb() {
this.db = new SQLite();
this.log += "openDatabase。。。";
// if (Device.device.platform)
this.db.openDatabase({
name: "data.db",
location: "default"
}).then((data) =>{
this.log += ("open ok " + JSON.stringify(data));
}, (err) => {
this.log += ("open err " + err.message + " " + JSON.stringify(err));
});
}
public executeSql(statement: string, parms:any) {
return this.db.executeSql(statement, parms);
}
}
和INIT sqlitehelper在app.components:
constructor(platform: Platform, sqliteHelper : SqliteHelper, events: Events) {
platform.ready().then(() => {
// Okay, so the platform is ready and our plugins are available.
// Here you can do any higher level native things you might need.
sqliteHelper.initDb();
events.publish("sqlite:inited", null);
StatusBar.styleDefault();
Splashscreen.hide();
});
}
我與platform.ready構造函數加載從第一個標籤頁的數據,對Android將運行導致err:無法讀取未定義的屬性executeSql。
如果我從按鈕點擊加載數據,沒關係。或者我把loaddata放到第二頁的構造函數中,這也沒關係。爲什麼?誰能幫助我,我想把代碼放到第一頁並在頁面啓動時加載數據。