【问题标题】:Insert provider for SQLiteObject ionic 3SQLiteObject ionic 3 的插入提供程序
【发布时间】:2017-11-01 07:58:45
【问题描述】:

我正在做一个关于 ionic 3 angular 4 的项目。我必须连接到数据库并做其他事情...... 所以我有一个页面(.ts .html .scss .module.ts),一个我使用 sql 的提供程序。所以我的问题是这样的,我有这个错误:

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

所以在 module.ts 中我添加了提供程序标志,我把 SQLiteObject。但现在我得到了这个新错误:

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

另外,如果我使用 SQLite,它总是需要 SQLiteObject 提供程序。无论如何,我从不使用 SQLite,只使用 SQLiteObject

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

我google了一下,发现SQLiteObject不是提供者,只是一个接口。

所以?任何想法?我可以放代码,但很长,如果你有什么想法请评论。

【问题讨论】:

    标签: sqlite angular ionic3


    【解决方案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 {}
    

    【讨论】:

      【解决方案2】:

      你说得对,SQLiteObject 不是提供者,但你正试图将它作为一个提供者导入。它是 SQLite 提供程序使用的类 Object,因此您可以从构造函数中保存对象,然后从那里将其用作 this.db。仅供参考:删除 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 ...", {});
              });
      }
      

      【讨论】:

        猜你喜欢
        • 2017-09-18
        • 2018-04-05
        • 2017-11-28
        • 2018-11-27
        • 2019-01-30
        • 2019-09-27
        • 1970-01-01
        • 1970-01-01
        • 2018-09-22
        相关资源
        最近更新 更多