我正在尝试从“angular2 / http”导入Http和Response,如下所示:
import { Http, Response } from 'angular2/http';
但是,当我运行我的应用程序时,系统尝试查找时出现404错误:
http://localhost:19102/Scripts/angular2/angular2.dev.js/http
我认为我的事物映射方式有问题,但我无法解决问题。
我在Visual Studio 2015中运行它。
这是我的system.js.config文件:
(function (global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'rxjs': 'node_modules/rxjs',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'angular2': 'Scripts/angular2/angular2.dev.js'
};
// 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 packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/router-deprecated',
'@angular/testing',
'@angular/upgrade'
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function (pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
packages: packages,
map: map,
bundles: {
'angular2': ['angular2/core', 'angular2/platform/browser']
}
}
// filterSystemConfig - index.html's chance to modify config before we register it.
if (global.filterSystemConfig) { global.filterSystemConfig(config); }
System.config(config);
})(本);
P.S。我是Angular的绝对新人,所以我仍在努力弄清楚事情是如何运作的。谢谢你的帮助。
答案 0 :(得分:0)
您需要从
更改导入import { Http, Response } from 'angular2/http';
到
import { Http, Response } from '@angular/http';
原因是因为在Angular 2 RC1中,角度模块的范围已更改为@angular
。它曾经是angular2
测试版,您正在显示的代码中导入。