I'm building an application that post an object_1 in a table then collect the ID inserted in the json response. After that, I want to post another object_2 that use also the ID inserted of my first object but the problem is that the insertedID is always undefined
//******** The interface **********
export interface PostResult__ {
fieldCount: number;
affectedRows: number;
insertId: number;
serverStatus: number;
warningCount: number;
message: string;
protocol41 : boolean;
changedRow :number;
}
//***** The service : ***********
export class AdressePostaleService {
constructor(private http: HttpClient) {}
addAdressePostale(adressepostale: AdressePostale): Observable<PostResult__>
{
return this.http.post<PostResult__>
(environment.apiUrl+'/api/adressespostale', adressepostale).pipe(
catchError(this.handleError)
);
}
}
********* The component / The function that post the object ***************
PostID : PostResult__[]=[];
//Function Ajouter Agence dans la BDD
AjouterAdresse(){
//Créer l'adresse postale
this._AdressePostale.Numero=this.firstFormGroup.value.Num_adresse;
this._AdressePostale.Voie=this.firstFormGroup.value.Voie_adresse;
this._AdressePostale.ID_Ville = this.VilleSelec.ID_Ville;
this.adresseservice.addAdressePostale(this._AdressePostale).subscribe(
adresse__=> this.PostID.push(adresse__));
console.log(this.PostID[0]);
}
Actual Results : console.log(this.PostID[0]); = Undefined
Excpetced Result : console.log(this.PostID[0]); = the json file with the last insertID