我正在尝试完成Angular之旅英雄教程的HTTP部分。
https://angular.io/docs/ts/latest/tutorial/toh-pt6.html
将app.module.ts从v1更改为v2后,应用程序不再加载,我在控制台中收到以下错误:
仪表板:16错误:(SystemJS)ctorParameters.map不是函数 TypeError:ctorParameters.map不是函数 在ReflectionCapabilities.parameters(http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:1780:49) 在Reflector.parameters(http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:1922:48) 在CompileMetadataResolver.getDependenciesMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14534:56) 在CompileMetadataResolver.getTypeMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14499:28) 在CompileMetadataResolver.getNgModuleMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14403:30) 在eval(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14324:52) at Array.forEach(native) 在CompileMetadataResolver.getNgModuleMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14311:46) 在RuntimeCompiler._compileComponents(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17063:49) at RuntimeCompiler._compileModuleAndComponents(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17001:39) 评估http://localhost:3000/app/main.js 加载http://localhost:3000/app/main.js时出错 在ReflectionCapabilities.parameters(http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:1780:49) 在Reflector.parameters(http://localhost:3000/node_modules/@angular/core/bundles/core.umd.js:1922:48) 在CompileMetadataResolver.getDependenciesMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14534:56) 在CompileMetadataResolver.getTypeMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14499:28) 在CompileMetadataResolver.getNgModuleMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14403:30) 在eval(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14324:52) at Array.forEach(native) 在CompileMetadataResolver.getNgModuleMetadata(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:14311:46) 在RuntimeCompiler._compileComponents(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17063:49) at RuntimeCompiler._compileModuleAndComponents(http://localhost:3000/node_modules/@angular/compiler/bundles/compiler.umd.js:17001:39) 评估http://localhost:3000/app/main.js 加载http://localhost:3000/app/main.js
时出错
文件之间的唯一区别是以下几行:
import { InMemoryWebApiModule } from 'angular-in-memory-web-api';
import { InMemoryDataService } from './in-memory-data.service';
我找到了一些答案,这些答案都归咎于内存中的角度网络API,但却有不同的错误和旧版本。因此,基于这些答案,我认为以下两个文件可能提供线索。
这是我的package.json:
{
"name": "angular-quickstart",
"version": "1.0.0",
"scripts": {
"start": "npm run lite",
"lite": "lite-server"
},
"license": "MIT",
"dependencies": {
"@angular/common": "~2.4.0",
"@angular/compiler": "~2.4.0",
"@angular/core": "~2.4.0",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "~2.4.0",
"@angular/platform-browser-dynamic": "~2.4.0",
"@angular/router": "~3.4.0",
"@angular/upgrade": "~2.4.0",
"angular-in-memory-web-api": "~0.1.16",
"core-js": "^2.4.1",
"reflect-metadata": "^0.1.8",
"rxjs": "5.0.1",
"zone.js": "^0.7.4"
},
"devDependencies": {
"concurrently": "^3.0.0",
"lite-server": "^2.2.2"
}
}
和我的systemjs.config.js
/**
* System configuration for Angular samples
* Adjust as necessary for your application needs.
*/
(function (global) {
System.config({
paths: {
// paths serve as alias
'npm:': 'node_modules/'
},
// map tells the System loader where to look for things
map: {
// our app is within the app folder
app: 'app',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
'@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js',
'@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js',
'@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js',
'@angular/http': 'npm:@angular/http/bundles/http.umd.js',
'@angular/router': 'npm:@angular/router/bundles/router.umd.js',
'@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js',
'@angular/upgrade': 'npm:@angular/upgrade/bundles/upgrade.umd.js',
// other libraries
'rxjs': 'npm:rxjs',
'angular-in-memory-web-api': 'npm:angular-in-memory-web-api/bundles/in-memory-web-api.umd.js'
},
// packages tells the System loader how to load when no filename and/or no extension
packages: {
app: {
main: './main.js',
defaultExtension: 'js'
},
rxjs: {
defaultExtension: 'js'
}
}
});
})(this);
我很确定它与angular-in-memory-web-api有关,它会成为某种配置问题。三江源。