2017-05-31 40 views
0

我正在研究离子3角4的项目。我必须连接到数据库并执行其他操作... 因此,我有一个页面(.ts .html .scss。 module.ts),我使用sql的提供者。所以我的问题是这样的,我有这样的错误:SQLiteObject插入提供程序离子3

core.es5.js:1084
错误错误:未捕获的(在承诺):错误:没有提供程序SQLiteObject!
错误:没有SQLiteObject的提供者!

所以在module.ts我添加在提供者标志我把SQLiteObject。但现在我得到这个新的错误:

compiler.es5.js:1540
未捕获错误:无法解析SQLiteObject的所有参数:(?)。

另外,如果我把SQLite的就是了总是SQLiteObject provider.Anyway我从来没有使用SQLite只是SQLiteObject

import { SQLiteObject } from '@ionic-native/sqlite'; 

我谷歌和我发现SQLiteObject不是提供商,但只是一个接口。

那么,任何想法?我可以把代码,但很长,如果你有一些想法,请评论。

回答

0

你是对的SQLiteObject不是一个提供者,但你试图导入它作为一个。它是SQLite提供程序使用的类对象,因此您可以从构造函数中保存该对象,然后从那里使用它作为this.db。 FYI:删除import { SQLiteObject }声明。

private db: SQLiteObject; 

constructor(private sqlite: SQLite) 
{ 
     this.sqlite.create({ 
      name: 'data.db', 
      location: 'default' 
     }) 
     .then((db: SQLiteObject) => { 
      this.db = db; //set the object to your own var 
      db.executeSql("CREATE TABLE IF NOT EXISTS ...", {}); 
     }); 
} 
1

您需要在您的app.module.ts文件中添加了类提供商:

import { SQLiteObject } from '@ionic-native/sqlite'; 

@NgModule({ 
    declarations: [ 
    MyApp 
    ], 
    imports: [ 
    // 
    ], 
    bootstrap: [IonicApp], 
    entryComponents: [ 
    MyApp 
    ], 
    providers: [{provide: ErrorHandler, useClass: IonicErrorHandler}, SQLiteObject] 
}) 

export class AppModule {}