angular 在初始化lowdb用了await ,调用这个服务的时候,会提示db是undefine,怎么破

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

import * as lowdb from 'lowdb';

import { ElectronService } from '../core/services';

  

@Injectable({

 providedIn: 'root'

})

export class LowdbService {

 private db: lowdb.LowdbAsync<any>;

 constructor( private elec:ElectronService) {

 this.initDatabase();

 }

 set( field: string, value: any ) {

 this.db.set( field, value ).write();

 }

 private async initDatabase() {

 const adapter = new this.elec.Adapter( this.elec.lowdbPath );

 this.db = await lowdb( adapter );

 this.db.defaults({

 a:123

 }).write()

 }

}
阅读 105
评论
    0 个回答
    撰写回答

    登录后参与交流、获取后续更新提醒

    相似问题
    推荐文章