Ionic 4“(未安装)SQLitePorter”

时间:2019-06-07 11:44:07

标签: ionic4

当我在devapp上运行我的应用程序(ionic4)时,终端上显示一条消息:

  

[console.warn]:“本机:尝试调用SQLitePorter.importSqlToDb,但未安装SQLitePorter”

     

[console.warn]:“安装SQLitePorter插件:'ionic cordova插件添加uk.co.workingedge.cordova.plugin.sqliteporter”

     

[console.error]:“未安装插件”

我尝试通过以下方式再次安装它:

ionic cordova plugin add uk.co.workingedge.cordova.plugin.sqliteporter

npm install @ionic-native/sqlite-porter

但是当我再次运行我的应用程序时,我仍然遇到相同的错误。

这是我的DatabaseService的代码:

export class DatabaseService {

  private dbReady: BehaviorSubject<boolean> = new BehaviorSubject(false);

constructor(private plt: Platform, private sqlite: SQLite, private sqlitePorter: SQLitePorter, private http: HttpClient) {

    console.log('début');
    this.plt.ready().then(() => {
      this.sqlite.create({
        name: 'flashcards.db',
        location: 'default'
      })
        .then((db: SQLiteObject) => {
          this.database = db;
          this.seedDatabase();
        })
        .then(() => console.log('Executed SQL'))
        .catch(e => console.log(e));
    });
    console.log('fin');  

seedDatabase() {

    this.http.get('assets/seed.sql', { responseType: 'text' })
      .subscribe(sql => {

        this.sqlitePorter.importSqlToDb(this.database, sql)
          .then(_ => {

            this.dbReady.next(true);
          })
      })
  }
}

getDatabaseState() {

    return this.dbReady.asObservable();
  }

And the code of the class that calls the service :

export class CategoriesPage implements OnInit {

constructor(private db: DatabaseService) {
  }

  ngOnInit() {

    console.log('début (categories');
    this.db.getDatabaseState().subscribe(rdy => {
      if (rdy) {
        this.db.getCategories().subscribe(categories => {
          this.categories = categories;
          console.log(this.categories);
        });
        this.cards = this.db.getCards();
      }
    });
    console.log('fin (categories)');
  }

谢谢:)

0 个答案:

没有答案