Can't understand the http module from angular, all works good, but when i insert new data and do the new request, it is in different order, the request get is executed before the POST
The init event (it works)
ngOnInit() {
this.refresh();
}
refresh(){
this.ps.getFamProv().subscribe((data: any) => {this.famProv = data.familias;});
}
The server log:
POST /api/provf/ 201 12.381 ms - 135
GET ALL
Then insert new item
onSubmit() {
//POST
var res=this.ps.addFamProv(this.formAddP.value.name,
this.formAddP.value.rfc);
this.modalService.dismissAll();
//CALLING THE REFRESH METHOD
this.refresh();
//TRY THIS
/*res.then( ()=>{
this.refresh();
console.log("refresh");
});*/
}
Server log (first get the data and then create the new item)
GET /api/provf 304 14.565 ms - -
CREATED PROV FAM
And the Service:
addFamProv(name, rfc) {
const obj = {
name: name,
rfc: rfc
};
return this.http.post(`${this.uri}/provf/`, obj).subscribe(res => {return res;} );
}
getFamProv() {return this.http.get(`${this.uri}/provf`);}
Use Await or Async ??