Angular-in-memory-web-api-page not found in Angular 4.2.2 CLI web-api
I am learning the Angular framework (using version 4.2.2) and following the Tour of Heroes instructions. The HTTP section of the tutorial uses angular-in-memory-web-api to simulate a web server api and I try to use it but it doesn't work. Message from browser console let me know Reply with status: 404 Not found for url: api / heroes I installed angular-in-memory-web-api using node install npm i angular-in-memory-web-api and this is my code (this is the same as the tutorial) implement the in-memory-web-api for api / heroes import module , which I will skip from the project.
source to share
Check app / in -memory-data.service.ts where createDb () method returns api endpoints . The returned object uses ES6 Object destructuring syntax , which associates an array of heroes with the heroes field in the object.
import { InMemoryDbService } from 'angular-in-memory-web-api';
export class InMemoryDataService implements InMemoryDbService {
createDb() {
const heroes = [
{ id: 0, name: 'Zero' },
{ id: 11, name: 'Mr. Nice' },
{ id: 12, name: 'Narco' },
{ id: 13, name: 'Bombasto' },
{ id: 14, name: 'Celeritas' },
{ id: 15, name: 'Magneta' },
{ id: 16, name: 'RubberMan' },
{ id: 17, name: 'Dynama' },
{ id: 18, name: 'Dr IQ' },
{ id: 19, name: 'Magma' },
{ id: 20, name: 'Tornado' }
];
return {heroes}; // !!!pay attention to this line; it creates api/heroes rest endpoint
}
}
source to share