ionic 4 / angular 6重新编译...无限循环

时间:2018-09-25 19:45:39

标签: angular ionic-framework electron ionic4

我正在使用带有Electron的Ionic 4 / Angular 6查询 .mdb 文件(ms access db),因此,我使用了database-js-adodb软件包来连接数据库并进行查询。

我的问题是,当我从 home.page.ts 调用select方法以使用database-js-adodb包查询数据库时,我的应用程序堆栈处于无限的重新编译循环中。

  

注意:   我在带电子的Ionic 3 / Angular 5应用程序中使用了相同的代码,它的工作原理就像一个魅力

ORM.service.ts

import { Injectable } from '@angular/core';

@Injectable({
  providedIn: 'root'
})
export class ORMService {
  // tslint:disable-next-line
  private ADODB = window.require('database-js-adodb');
  public connection: any;
  constructor() {
    this.connect();
  }

  private connect() {
        this.connection = this.ADODB.open({
            Database: 'src/assets/data.mdb'
        });
  }

  select(tableName: string, fields: string | string[], whereStatment? : string): Promise<any> {
    return new Promise( async (resolve, reject) => {
      fields = typeof fields == 'object' ? fields.join(',') : fields;
      let queryString = whereStatment ? 
                        `SELECT ${fields} FROM ${tableName} WHERE ${whereStatment}` :
                        `SELECT ${fields} FROM ${tableName}`;
      try {
        let rows = await this.connection.query(queryString);
        resolve(rows);
      } catch (error) {
        console.log(error);
        reject(error);
      } finally {
        await this.connection.close();
      }
    })
  }

}

home.page.ts

import { Component } from '@angular/core';
import { ORMService } from '../services/orm/ORM.service';

@Component({
  selector: 'app-home',
  templateUrl: 'home.page.html',
  styleUrls: ['home.page.scss'],
})
export class HomePage {

  constructor(private ORM: ORMService) {
    this.ORM.select('users','*').then((rows) => {
      console.log(rows);
    });
  }
}

0 个答案:

没有答案