I m trying to create a
dans les services de mémoire` , mais quand j'ai essayé de le poster, il donne un POST ERROR 404 (NOT FOUND). comment réparer ce un essayé de copier le tour de héros mais a obtenu cette erreur et je pense que je l'ai obtenu correctement mais son bizarre que je reçois l'erreur 404 (NOT FOUND).
SERVICES EN MÉMOIRE
@Injectable({
providedIn: 'root'
})
export class InMemoryDataService implements InMemoryDbService {
createDb() {
const serials = [
{id: 1, deliveryReceiptDetailsId: 0, itemCode:'testing', qtyReceived:0 },
{id: 2, deliveryReceiptDetailsId: 0, itemCode:'sample1', qtyReceived:0 },
{id: 3, deliveryReceiptDetailsId: 0, itemCode:'sample2', qtyReceived:0 },
{id: 4, deliveryReceiptDetailsId: 0, itemCode:'sample3', qtyReceived:0 },
{id: 5, deliveryReceiptDetailsId: 0, itemCode:'sample4', qtyReceived:0 },
{id: 6, deliveryReceiptDetailsId: 0, itemCode:'sample5', qtyReceived:0 },
];
console.log(serials)
return {serials};
}
SERVICES
const httpOptions = {
headers: new HttpHeaders({
'Content-Type' : 'application/json',
'Authorization' : 'my-auth-token'
})
}
@Injectable({
providedIn: 'root'
})
export class SerialCodeService {
url = 'api/serials';
constructor(private http: HttpClient) { }
getHeroes(): Observable<SerialCodeDTO[]> {
return this.http.get<SerialCodeDTO[]>(this.url)
.pipe(
catchError(this.handleError)
);
}
/** POST: add a new hero to the database */
addHero(serial: SerialCodeDTO): Observable<SerialCodeDTO> {
return this.http.post<SerialCodeDTO>(this.url, serial, httpOptions)
.pipe(
catchError(this.handleError)
);
}
0 votes
Est-ce que votre appel GET fonctionne bien ? ou est-ce que c'est le POST qui échoue ?
0 votes
Les deux GET et POST échouent
0 votes
@mishart Pourriez-vous utiliser ceci stackblitz et fournir une reproduction minimale de l'erreur et la partager ?
0 votes
stackblitz.com/edit/http-client-crud-in-memory-api-hzdsvd @NarenMurali