My API returns this JSON, it's the same employee which is present 2 times in my database. I can't delete it in my database, also how can I print only 1 of them when I make my get in angular? Or when I make my *ngfor:"let e of employee", how can I print only the first result?
getEmployee(id: string){
return this.http.get<any>(this.localUrlAPI "/employee/getEmployee/" id)
.pipe(map((res:any)=>{
return res.Data;
}))
}
{
"Data":[
{
"IdEmployee": "1",
"Name": "Jacob"
}
{
"IdEmployee": "1",
"Name" ; "Jacob"
}
]
}
CodePudding user response:
so you want to remove duplicates, there are many approaches, this is one:
.pipe(map((res:any)=>{
const uniqueData = new Map<number, any>();
for (const data of res.Data) {
uniqueData.set(data.id, data);
}
return Array.from(uniqueData.values());
}))
