2017-08-13 55 views
0

我的错误:获取错误ionic3项目中'SQLite'类型不存在属性'openDatabase'?

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 
     ))`, {});    
    }} 

离子版本的详细信息

离子框架:3.6.0

离子应用程序脚本:2.1.3

方芯:4.1.3

角度编译CLI:4.1.3

节点:8.2.1

OS平台:Linux 4.4

导航器平台:Linux x86_64

用户代理:Mozilla/5.0(X11; Linux的x86_64的)为AppleWebKit/537.36(KHTML,例如Gecko)Chrome浏览器/ Safari浏览器60.0.3112.78/537.36

我想:

npm install --save @ionic-native/sqlite 

但并没有帮助。

+0

您是否找到了解决方案? – robbannn

回答

0

您应该将SQLite注入您的constructor。并且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(...); 
} 

... 
相关问题