2016-12-26 78 views
2

I'm trying to implement this simple example given in ionic 2 doc: http://ionicframework.com/docs/v2/native/sqlite/sqlitePlugin錯誤而在離子2

使用SQLite我想,例如在MAC(執行離子項目的'www\test.sqlite'文件夾下放置在分貝的查詢)和i得到兩者上的瀏覽器和iOS模擬器此錯誤(沒有按」在設備上要麼噸工作):

的ReferenceError:sqlitePlugin沒有定義

我已經加入科爾多瓦-源碼存儲插件離子項目。

代碼:

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

回答

0

嘗試移動你的邏輯構造出來的。

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

試過,仍然給我同樣的錯誤。 – Deepak