2017-08-13 1 views
0

マイエラー:エラーを取得していますプロパティ 'openDatabase'がionic3プロジェクトの 'SQLite'型に存在しませんか?

Runtime Error Uncaught (in promise): TypeError: _this.sqlstorage.openDatabase is not a function TypeError: _this.sqlstorage.openDatabase is not a function at http://localhost:8100/build/main.js:67:30 at t.invoke (http://localhost:8100/build/polyfills.js:3:9283) at Object.onInvoke (http://localhost:8100/build/vendor.js:4508:37) at t.invoke (http://localhost:8100/build/polyfills.js:3:9223) at r.run (http://localhost:8100/build/polyfills.js:3:4452) at http://localhost:8100/build/polyfills.js:3:14076 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4499:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9888) at r.runTask (http://localhost:8100/build/polyfills.js:3:5143)

スタック

Error: Uncaught (in promise): TypeError: _this.sqlstorage.openDatabase is not a function TypeError: _this.sqlstorage.openDatabase is not a function at http://localhost:8100/build/main.js:67:30 at t.invoke (http://localhost:8100/build/polyfills.js:3:9283) at Object.onInvoke (http://localhost:8100/build/vendor.js:4508:37) at t.invoke (http://localhost:8100/build/polyfills.js:3:9223) at r.run (http://localhost:8100/build/polyfills.js:3:4452) at http://localhost:8100/build/polyfills.js:3:14076 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4499:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9888) at r.runTask (http://localhost:8100/build/polyfills.js:3:5143) at c (http://localhost:8100/build/polyfills.js:3:13535) at http://localhost:8100/build/polyfills.js:3:14107 at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9967) at Object.onInvokeTask (http://localhost:8100/build/vendor.js:4499:37) at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9888) at r.runTask (http://localhost:8100/build/polyfills.js:3:5143) at o (http://localhost:8100/build/polyfills.js:3:2203) at HTMLDocument.invoke (http://localhost:8100/build/polyfills.js:3:10985)

マイHome.tsファイル:

import { Component } from '@angular/core'; 
import { NavController,Platform } from 'ionic-angular'; 
import {SQLite} from "@ionic-native/sqlite"; 

@Component({ 
    selector: 'page-home', 
    templateUrl: 'home.html' 
}) 
export class HomePage { 
    sqlstorage: SQLite; 
    items: Array<Object>; 

    constructor(public navCtrl: NavController, private platform: Platform) { 
    this.platform.ready().then(() => { 
      for (var i = 100000 - 1; i >= 0; i--) { 
       console.log("test"); 
        } 
      this.sqlstorage = new SQLite(); 
      this.sqlstorage.openDatabase({name: "items.db", location: "default"}).then(() => { 
       this.createTables(); 
       this.findAll(); 
      }, (err) => { 
       console.log("!!! ", err); 
      }); 
     }); 

    } 

    public createTables(){ 
     this.sqlstorage.executeSql(`create table if not exists items(
      reference CHAR(10) PRIMARY KEY, 
      name CHAR(30), 
      qMin FLOAT, 
      qReal FLOAT 
     ))`, {});    
    }} 

イオンのバージョンが

イオンFrameworkの詳細:3.6.0

イオンのAppスクリプト:2.1.3

角度コア:4.1.3

角度コンパイラCLI:4.1.3

ノード:8.2.1

OSプラットフォーム:Linuxの4.4

ナビゲータプラットフォーム:Linux x86_64

ユーザエージェント:Mozilla/5.0(X11;

npm install --save @ionic-native/sqlite 

をしかし、助けにはならなかった:Linuxのx86_64で)のAppleWebKit/537.36(KHTML、ヤモリなど)クローム/ 60.0.3112.78 Safariは/ 537.36

は、私が試してみました。

+0

ソリューションを見つけましたか? – robbannn

答えて

0

constructorSQLiteを注入する必要があります。 SQLiteにはopenDatabase()という機能がないようです。 documentationは、create(config:SQLiteDatabaseConfig)を作成するにはというデータベースを使用すると言います。

... 

private db: SQLiteObject; 

constructor(private sqlite: SQLite, private platform: Platform) { 
    platform.ready().then(() => { 
     sqlite.create({ 
      name: "items.db", 
      location: "default" 
     }) 
     .then(db => { 
      this.db = db; 
      this.createTables(); 
     } 
    }); 
} 

createTables(){ 
    this.db.executeSql(...); 
} 

... 
関連する問題