Sivo 悉见

Cannot find module 'angular-in-memory-web-api'

匿名 · 更新于 2017/8/23

First, you need to npm i angular2-in-memory-web-api --save

Then in main.ts:

import{InMemoryBackendService, SEED_DATA } from 'angular2-in-memory-web-api'

in src/system-config.js:

const barrels: string[] = [
  // Angular specific barrels.
  '@angular/core',
  '@angular/common',
  '@angular/compiler',
  '@angular/forms',
  '@angular/http',
  '@angular/router',
  '@angular/platform-browser',
  '@angular/platform-browser-dynamic',


  // Thirdparty barrels.
  'rxjs',
  'angular2-in-memory-web-api',

  // App specific barrels.
  'app',
  'app/shared',
  /** @cli-barrel */
];



    // Apply the CLI SystemJS configuration.
    System.config({
      map: {
        '@angular': 'vendor/@angular',
        'rxjs': 'vendor/rxjs',
        'main': 'main.js',
        'angular2-in-memory-web-api': 'vendor/angular2-in-memory-web-api'
      },

and add this to angular-cli-build.js in your projects root directory:

   'angular2-in-memory-web-api/**/**/*.js'`

Finally restart the server and run ng build before ng serve.

转载:https://stackoverflow.com/questions/38275364/angular2-in-memory-web-api-404-error