Good morning, I’m starting my ionic journey and I have the following scenario:
I created an app, a simple CRUD, where you have a list of items and a modal to register a new item, when I close the modal clicking save the new item is sent to my API, saved in the database and returned to the list. This works fine in the ionic serve but when I squeeze in the device the item just saves in the bank but does not return to list. My Class Functions:
getDados() {
//retorno de Dados
this.service.getData()
this.service.getData()
.then((lancamentos: Array<any>) => {
this.lancamentos = lancamentos;
}, (error) => {
console.log('Erro ao listar ',error);
})
}
postDados(lancamento) {
this.service.postData(lancamento.value)
.then((data) => {
if(data) {
console.log(data),
this.close();
this.presentToast();
}
}, (error) => {
console.log('Erro ao cadastrar. ', error);
this.presentToastErro();
}
);
}
minhas funções provider para API:
getData() {
return new Promise((resolve, reject) => {
this.http.get(this.api + 'apiRecupera.php')
.map(res => res.json())
.subscribe(data => {
resolve(data);
}, error => {
reject(error);
});
});
}
postData(parans) {
let headers = new Headers({ 'Content-Type' : 'application/x-www-form-urlencoded' });
return new Promise((resolve, reject) => {
this.http.post(this.api + "apiCadastroCont.php", JSON.stringify(parans), {
headers:headers,
method:"POST"
})
.map(res => res.json())
.subscribe(data => {
resolve(data);
}, error => {
reject(error);
})
});
}`Preformatted text`