I am facing an issue with my Angular service:
import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';
import { Observable } from 'rxjs';
import { person } from '../interfaces/iperson';
import { item } from '../interfaces/iitem';
@Injectable({
providedIn: 'root'
})
export class PeopleserviceService {
constructor(private http: HttpClient) { }
getPersonData(): Observable<person[]> {
return this.http.get<person[]>('/assets/data/people.json');
}
completeTransaction(p: person, i: item){
return this.http.get<person[]>('/assets/data/people.json').toPromise().then(peopleData => {
if (!peopleData) {
return Promise.reject(new Error('No data received'));
}
for (const pers of peopleData) {
if (pers.id === p.id) {
pers.balance -= i.price;
break;
}
}
return this.http.put('/assets/data/people.json', JSON.stringify(peopleData)).toPromise();
});
}
}
This setup is resulting in the following error:
ERROR Error: Uncaught (in promise): HttpErrorResponse: {"headers":{"normalizedNames":{},"lazyUpdate":null},"status":404,"statusText":"Not Found","url":"http://127.0.0.1:4200/assets/data/people.json","ok":false,"name":"HttpErrorResponse","message":"Http failure response for http://127.0.0.1:4200/assets/data/people.json: 404 Not Found","error":"<!DOCTYPE html>\n<html lang=\"en\">\n<head>\n<meta charset=\"utf-8\">\n<title>Error</title>\n</head>\n<body>\n<pre>Cannot PUT /assets/data/people.json</pre>\n</body>\n</html>\n"}
Angular 17
core.mjs:9171:22
Angular 2
RxJS 6
Angular 14
Is there a way to make this angular page write locally to a file?
I have explored options like using the localforage package, but it doesn't seem to be working as expected.