Angular2 Tutorial (Tour of Heroes): Cannot find module 'angular2-in-memory-web-api'

前端 未结 29 2316
青春惊慌失措
青春惊慌失措 2020-11-29 06:25

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

29条回答
  •  感情败类
    2020-11-29 06:37

    If using angular cli to build your angular2 app, including the angular2-in-memory-web-api involves three steps:

    1. 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' }
      };
      
    2. Add

      angular2-in-memory-web-api/**/*.+(js|js.map)' 
      

    to the vendorNpmFiles array in the angular-cli-build.js file like ofShard mentioned;

    1. 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.

提交回复
热议问题