I have followed the Tutorial. After changing app/maint.ts
in the Http chapter I get the error when starting the app via command line:
ap
If using angular cli to build your angular2 app, including the angular2-in-memory-web-api involves three steps:
add the api to the system-config.ts file (inside the src subdirectory) like below:
/** Map relative paths to URLs. */
const map: any = {
'angular2-in-memory-web-api': 'vendor/angular2-in-memory-web-api'
};
/** User packages configuration. */
const packages: any = {
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }
};
Add
angular2-in-memory-web-api/**/*.+(js|js.map)'
to the vendorNpmFiles array in the angular-cli-build.js file like ofShard mentioned;
Of course, add to the package.json as described by traneHead; for 2.0.0-rc.3 I use the version below:
"angular2-in-memory-web-api": "0.0.13"
I find this link "Adding material2 to your project" explains the process of adding third-party libraries quite clearly.
The main answer helped me: change
'angular2-in-memory-web-api': { defaultExtension: 'js' },
to
'angular2-in-memory-web-api': { main: 'index.js', defaultExtension: 'js' }
Here is what worked for me:
I noticed that the package.json had the following version:
"angular2-in-memory-web-api": "0.0.20"
Note the "2" in the name.
However when referencing InMemoryWebApiModule it was using 'angular-in-memory-web-api' without the 2 in the name. So I added it and it resolved the issue:
import { InMemoryWebApiModule } from 'angular2-in-memory-web-api';
Note: I found this in notice section of https://github.com/angular/in-memory-web-api
As of v.0.1.0, the npm package was renamed from angular2-in-memory-web-api to its current name, angular-in-memory-web-api. All versions after 0.0.21 are shipped under this name. Be sure to update your package.json and import statements.
As of October 17, 2017, the tutorial fails to mention that angular-in-memory-web-api
is not included in a standard CLI build, and must be installed separately. This can be easily done with npm
:
$ npm install angular-in-memory-web-api --save
This automatically handles the necessary changes to package.json
, so you don't need to make edits yourself.
This thread is quite confusing as the Angular CLI has changed significantly since this thread was started; a problem with many rapidly-evolving APIs.
angular-in-memory-web-api
has been renamed; it drops the 2 from angular2 to simply angular
systemjs.config.js
no longer exists.npm
's package.json
should not be edited directly; use the CLI.As of October 2017, the best fix is to simply install it yourself using npm
, as I mentioned above:
$ npm install angular-in-memory-web-api --save
Good luck out there!
The simplest solution I could think of was to install the package with npm and restart the server:
npm install angular-in-memory-web-api --save
I almost installed the angular2-in-memory-web-api package, but the npm page says:
All versions after 0.0.21 are (or soon will be) shipped under angular-in-memory-web-api.
Note: This solution worked for a project that was created with the CLI tools, which does not list the package as a dependency, and might not solve the problem for projects that were created with the Quickstart seed, which does list the package as a dependency.
The Best way is to install it using NPM e.g
npm install git+https://github.com/itryan/in-memory-web-api/ --save
it will add required reference