更新时间:2022-02-19 23:40:41
您需要使用systemjs映射包@angular/core
,@angular/common
...等.否则,它将如何知道在哪里找到它们?
You need to map your packages @angular/core
,@angular/common
... etc using systemjs. Otherwise, how would it know where to find them?
创建一个名为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);
然后,在您的index.html
中,导入您创建的文件:
Then, in your index.html
, import the file you created:
<script src="systemjs.config.js"></script>
<script>
System.import('app').catch(function(err){ console.error(err); });
</script>
请注意,您应该从index.html
System.config({
packages: {
app: {
format: 'register',
defaultExtension: 'js'
}
}
});
上面的代码摘自最底部的 angular2快速入门页页面的内容.
The code above is taken from angular2 quick start page at the very bottom of the page.