I want to update data in InMemoryDBService but it doesn't work. Propably it's a problem with client.id. I think that because in client.service.ts i tryed display in console.log user.id (like you can see in my code) but I have undefined. But client.name display correctlly text. So i made hello object with id (look at my code) but it doesn't work too. I don't have any error. This code doesn't change deta of clients and I don't have idea why. So look at my code: clients-data.service
createDb(){
const clients = [
{
id: 1,
name: 'Jan Kowalski',
city: 'Lublin',
streetNumber: 4,
flatNumber: 12
},
{
id: 2,
name: 'Jan Nowak',
city: 'Lublin',
streetNumber: 4,
flatNumber: 12
},
{
id: 3,
name: 'Marian Stefański',
city: 'Lublin',
streetNumber: 4,
flatNumber: 12
},
];
return { clients };
}
genId(clients: Client[]): number {
return clients.length > 0 ? Math.max(...clients.map(client => client.id)) + 1 : 11;
}
client.service.ts
private clientsURL = 'api/clients';
updateClient(client: Client): Observable<any> {
const hello = {id: 2, name: 'Hello World', city: 'Test', streetNumber: 'Test', flatNumber: 3};
return this.http.put(this.clientsURL, client, this.httpOptions).pipe(
tap(_ => console.log(`updated hero id=${client.id}`)),
catchError(this.handleError<any>('updateHero'))
);
}
client-details.components.ts
update(): void {
if(this.client){
this.clientService.updateClient(this.updateClientForm.value as Client)
.subscribe(() => this.goBack());
}
}
Where I make a mistake?