I have a problem when using the router.navigate.Before i added the router code my code worked well but now its giving me this error "ERROR TypeError: Cannot read property 'init' of undefined" this is my code:
this is the constructor:
export class IndexedDBService {
constructor(
private _store: Store<AppState>,
private _electron: ElectronService,
private _device: Device,
private userService: UtilizadoresService,
private workTypesService: TiposTrabalhoService,
private modelTypesService: TiposModeloService,
private modelService: ModelosService,
private clientService: ClientesService,
private paymentMethodService: FormasPagamentoService,
private salesNotSent: VendasPorEnviarService,
private groupTypeWork: GruposTiposTrabalhoService,
private companies: CompanyService,
private _alertCtrl: AlertController,
private _translate: TranslateService,
private _router: Router,
) {}
this is when i call the router:
this._router.navigate(['login']);
this is when i call my db.init function which is in my app.module:
export function dbInitializer(db: IndexedDBService) {
return () => db.init();
}
this is my db init function:
public async init(): Promise<string> {
console.warn(
isDevMode() ? '[Activation Disabled] Running in dev mode!' : ''
);
const activationCode: string = localStorage.getItem(kActivation);
let compareCode: string;
if (this._electron.isElectronApp) {
compareCode = encrypt(this._electron.ipcRenderer.sendSync('device-info'));
} else {
compareCode = encrypt(
`${this._device.manufacturer}|${this._device.model}|${this._device.uuid}`
);
}
// bypass activation when in dev mode
if (activationCode === compareCode || isDevMode()) {
try {
const isDbCreated = await IdbHelper.idbCon.initDb(this.getDbSchema());
if (isDbCreated === true) {
await (this.overwriteDB());
return 'database created';
} else {
await this.overwriteDB();
return 'database opened';
}
} catch (error) {
throw error.message;
}
} else {
return undefined;
}
}
Thank you for your help
dbInitializer(private db: IndexedDBService) { return () => this.db.init();