Home > Software engineering >  Angular don't print informations API
Angular don't print informations API

Time:02-02

I changed my API REST and when i swap, she don't print the informations.

My Api send me this json structure :

{
  "Data": [
    {
      "Id": "#AJUST",
      "Nom": "TRONY",
      "Prenom": "JACOB",
    }
  ]
}

I make this request with angular :

getEmployee(){
    return this.http.get<any>(this.localUrlAPI "/salarie/GetAllEmployee")
    .pipe(map((res:any)=>{
      return res;
    }))
  }

getAllEmployee(){
    this.api.getEmployee()
    .subscribe(res=>{
      this.EmployeeData = res;
    })
  }

Why did that print me nothing in my application. Thx for the time that you take to help me.

CodePudding user response:

Since you want to get the array in Data, with map rxjs operator to get res.Data instead of res.

map((res: any) => {
    return res.Data;
})
getEmployee() {
  return this.http.get<any>(this.localUrlAPI "/salarie/GetAllEmployee").pipe(
    map((res: any) => {
      return res.Data;
    })
  );
}

And would suggest specifying EmployeeData as array type rather than any.

EmployeeData!: any[];

Sample Demo on StackBlitz

  •  Tags:  
  • Related