Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

296
Visualizações
angular-in-memory-web-api displays error 404

I done the heroes-tour and I want to do something similar but I have a problem with understand angular-in-memory-web-api. Look at my code: 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() { }
}

clients.service.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)
  }
}

app.module.ts

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

But in console display an error 404 for api/client. Where I make mistake?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

your createDb() needs to return an Object of key/value pairs, not an array.

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

Or just change your return line to return {clients};

about 4 years ago · Juan Pablo Isaza Relatório

0

I think the error is in your path.

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

Check your entire route, maybe the error is there.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda