微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

import – Angular2教程(英雄之旅):找不到模块’angular2-in-memory-web-api’

我已经跟随 Tutorial.改变app / maint.ts在Http章后,我得到错误,当启动应用程序通过命令行:

app/main.ts(5,51): error TS2307: Cannot find module ‘angular2-in-memory-web-api’.

(Visual Studio Code给我在main.ts中的相同的错误 – 红色波浪下划线。)

这里是我的systemjs.config.js:

/**
 * System configuration for Angular 2 samples
 * Adjust as necessary for your application needs.
 */
(function(global) {
  // map tells the System loader where to look for things
  var map = {
    'app':                        'app',// 'dist','@angular':                   'node_modules/@angular','angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api','rxjs':                       'node_modules/rxjs'
  };
  // packages tells the System loader how to load when no filename and/or no extension
  var packages = {
    'app':                        { main: 'main.js',defaultExtension: 'js' },'rxjs':                       { defaultExtension: 'js' },'angular2-in-memory-web-api': { defaultExtension: 'js' },};
  var ngPackageNames = [
    'common','compiler','core','http','platform-browser','platform-browser-dynamic','router','router-deprecated','upgrade',];
  // Add package entries for angular packages
  ngPackageNames.forEach(function(pkgName) {
    packages['@angular/'+pkgName] = { main: pkgName + '.umd.js',defaultExtension: 'js' };
  });
  var config = {
    map: map,packages: packages
  }
  System.config(config);
})(this);

这里是我的应用程序/ main.ts:

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

import { InMemoryBackendService,SEED_DATA } from 'angular2-in-memory-web-api';
import { InMemoryDataService }               from './in-memory-data.service';

// The usual bootstrapping imports
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 }),// in-mem server
    provide(SEED_DATA,{ useClass: InMemoryDataService })     // in-mem server data
]);
对我来说,唯一的解决方案是将angular2-in-memory-web-api升级到0.0.10。

在package.json中设置

'angular2-in-memory-web-api': '0.0.10'

在dependecies块中,并在systemjs.config.js中设置

'angular2-in-memory-web-api': { main: 'index.js',defaultExtension: 'js' }

在packages对象中。

原文地址:https://www.jb51.cc/angularjs/146258.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐