0
Personal I am new in IONIC/Angular and I do not understand yet very well Promise/Observable and would like a help ! I have the following situation:
- User clicks on a button that will fetch information in the mobile Sqlite;
- A foreach is made on return and called a webapi (http post) passing for each record the API;
- At the end of the foreach I will execute 2 commands to delete the Sqlite tables;
- And finally give a message to the user
However, I cannot define this sequence, in my code it deletes, gives the message to the user and then calls the API for each record. Below is an excerpt from the code
SincronizarSistema() {
let loading: Loading = this.showLoading('Sincronizando...');
this.voucherService.sincronizarPedidoDetalheSistema()
this.pedidosDetalhe = [];
this.pedidosDetalheBase = [];
this.carregarEventos();
loading.dismiss();
this.showAlert('Sincronização realizada com sucesso !')}
sincronizarPedidoDetalheSistema() {
this.getDB().then(() => {
let listaPedidosDetalhe: PedidoDetalhe[];
this.retornaPedidosDetalheBaixados()
.then((pedidosDetalhe: PedidoDetalhe[]) => {
listaPedidosDetalhe = pedidosDetalhe
listaPedidosDetalhe.forEach(element => {
this.baixaPedidoDetalheSistema(element.idPedidoDetalhe)
.subscribe(pedidoDetalhe => {
console.log(`Pedido ${element.idPedidoDetalhe} baixado com sucesso !`)
}, error => {
console.log('Erro ao baixar pedido ', error)
})
});
console.log("chegou aqui")
this.db.executeSql('DELETE FROM tblPedidoDetalhe', [])
this.db.executeSql('DELETE FROM tblEventoSincronismo', [])
})
});}
This case would even work, but I would delete the bases more than once without need (processing without need)
– user3658253