I get the Object essensplan
const essensplan = [
{ id: 1, essenProWoche: [11, 14, 17, 20, 12] },
...
{ id: 8, essenProWoche: [15, 14, 13, 12, 11] }
];
from an emulated server and I want the possibility for the user to change each value of the array essenProWoche and give it back to the server.
I tried
<div>
<label>Änderungen:
<input [(ngModel)]="essensplan.essenProWoche" placeholder="Name">
</label>
</div>
which doesn't work because it's not returned as an array
and
<label *ngFor="let id of essensplan.essenProWoche; let i = index">
<input type="number" [(ngModel)]="essensplan.essenProWoche[i]">
</label>
which changes the values live in the browser, but they are not saved.
I save the inputs by the following functions:
essensplan-detail.component.ts
save(): void {
this.essensplanService.updateEssensplan(this.essensplan)
.subscribe(() => this.goBack());
}
essensplan.service.ts
updateEssensplan(essensplan: Essensplan): Observable<any> {
return this.http.put(this.speisekarteUrl, essensplan, httpOptions).pipe(
tap(_ => this.log(`updated essensplan id=${essensplan.id}`)),
catchError(this.handleError<any>('updateEssensplan'))
const essensplan ={ id: 1, essenProWoche: [11, 14, 17, 20, 12] };