Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

295
Views
angular-in-memory-web-api muestra el error 404

Hice el recorrido de los héroes y quiero hacer algo similar, pero tengo un problema para entender angular-in-memory-web-api. Mira mi código: clients-data.service.ts

 import { Injectable } from '@angular/core'; import { InMemoryDbService } from 'angular-in-memory-web-api'; @Injectable({ providedIn: 'root' }) export class ClientsDataService implements InMemoryDbService{ createDb(){ const clients = [ {id: 1, name: 'Jan Kowalski'}, {id: 2, name: 'Grzegorz Brzęczyszczykiewicz'}, {id: 3, name: 'Paweł Nowak'}, ]; return clients; } constructor() { } }

clientes.servicio.ts

 import { HttpClient } from '@angular/common/http'; import { Injectable } from '@angular/core'; import { Observable, of } from 'rxjs'; import { Client } from './client'; @Injectable({ providedIn: 'root' }) export class ClientService { private clientsURL = 'api/clients'; constructor( private http: HttpClient, ) { } getClients(): Observable<Client[]> { return this.http.get<Client[]>(this.clientsURL) } }

aplicación.módulo.ts

 //... HttpClientInMemoryWebApiModule.forRoot( ClientsDataService, { dataEncapsulation: false } ) //...

Pero en la consola muestra un error 404 para api/client. ¿Dónde me equivoco?

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

su createDb() necesita devolver un objeto de pares clave/valor, no una matriz.

 createDb() { const clients = [ {id: 1, name: 'Jan Kowalski'}, {id: 2, name: 'Grzegorz Brzęczyszczykiewicz'}, {id: 3, name: 'Paweł Nowak'}, ]; return { clients: clients } }

O simplemente cambie su línea de devolución para return {clients};

about 4 years ago · Juan Pablo Isaza Report

0

Creo que el error está en tu camino.

 private clientsURL = 'http://entire-url/api/clients';

Revisa toda tu ruta, quizás el error esté ahí.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!