0

I would like to use angular2-in-memory-web-api but I get these errors :

GET http://localhost:3000/node_modules/angular2-in-memory-web-api/index.js.map 404 (Not Found)
GET http://localhost:3000/node_modules/angular2-in-memory-web-api/in-memory-backend.service.js.map 404 (Not Found)
GET http://localhost:3000/node_modules/angular2-in-memory-web-api/http-status-codes.js.map 404 (Not Found)

In the angular2-in-memory-web-api folder I have these files with extension .js and .d.ts but not .js.map

I read this Angular2 Tutorial (Tour of Heroes): Cannot find module 'angular2-in-memory-web-api' and test every solutions but it still doesn't work for me.

Here my code:

boot.ts :

// Imports for loading & configuring the in-memory web api
 import { provide }    from '@angular/core';
 import { XHRBackend } from '@angular/http';
 import 'rxjs/Rx';
 import 'rxjs/add/operator/map';

 import { InMemoryBackendService, SEED_DATA } from '../node_modules/angular2-in-memory-web-api';
 import { FavoriDataBase}               from './favori/favori-database';

 import { bootstrap }      from '@angular/platform-browser-dynamic';
 import { HTTP_PROVIDERS } from '@angular/http';
 import { AppComponent }   from './app.component';

 bootstrap(AppComponent, [
HTTP_PROVIDERS, 
provide(XHRBackend, { useClass: InMemoryBackendService }),
provide(SEED_DATA,  { useClass: FavoriDataBase })]);

In systemjs.config.js I have this line 'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' } And in package.json "angular2-in-memory-web-api": "0.0.10" I also updated angular2-in-memory-web-api in my console.

Everything worked find before I decide to use 'angular2-in-memory-web-api', I was using real http url to catch data and now I need to use "in folder url" to catch data of a created database (initially empty).

My database class:

export class FavoriDataBase {
createDb() {
let database= [];
return {database};
 }
}

Thanks by advance for any help !

Community
  • 1
  • 1
slidefizz
  • 257
  • 5
  • 12

2 Answers2

0

It's a bug. Here's the issue. https://github.com/angular/in-memory-web-api/issues/7

cyberwombat
  • 38,105
  • 35
  • 175
  • 251
0

I had to explicitly specify the providers:

providers: [
    HTTP_PROVIDERS,
    appRoutingProviders,
    { provide: XHRBackend, useClass: InMemoryBackendService },
    { provide: SEED_DATA, useClass: MyData }
  ],

where MyData is the class containing your fake data.

The description of the in-memory-api in the quickstart docs didn't mention this, but it worked for me.

Mark Williams
  • 2,268
  • 1
  • 11
  • 14