注意:我不使用 Angular Cli。
我添加了@angular2-material/core包。然后我安装了其他 angular2-material 组件,例如@angular2-material/button、@angular2-material/card等。
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',
'@angular2-material': 'node_modules/@angular2-material',
// <--------------added this above line----------------------
};
// 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': { main: 'index.js', defaultExtension: 'js' },
};
var ngPackageNames = [
'common',
'compiler',
'core',
'forms',
'http',
'platform-browser',
'platform-browser-dynamic',
'router',
'router-deprecated',
'upgrade',
];
//<------------------added this below part--------------------------------
var materialPackages=[
'core',
//'button',
//'card',
'list',
];
materialPackages.forEach(function(pkgName) {
packages['@angular2-material/'+pkgName] = { format: 'cjs', defaultExtension: 'js'};
});
//<----------------------till here---------------------------------
// Individual files (~300 requests):
function packIndex(pkgName) {
packages['@angular/'+pkgName] = { main: 'index.js', defaultExtension: 'js' };
}
// Bundled (~40 requests):
function packUmd(pkgName) {
packages['@angular/'+pkgName] = { main: '/bundles/' + pkgName + '.umd.js', defaultExtension: 'js' };
}
// Most environments should use UMD; some (Karma) need the individual index files
var setPackageConfig = System.packageWithIndex ? packIndex : packUmd;
// Add package entries for angular packages
ngPackageNames.forEach(setPackageConfig);
var config = {
map: map,
packages: packages
};
System.config(config);
})(this);
当我运行我的应用程序时,我看到以下错误,
加载资源失败:服务器响应状态为 404(未找到) http://localhost:3000/node_modules/@angular2-material/sidenav/加载资源失败:服务器响应状态为 404(未找到) ) http://localhost:3000/node_modules/@angular2-material/toolbar/ 加载资源失败:服务器响应状态为 404 (Not Found) localhost/:16 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular2-material/button (...)(匿名函数) @ localhost/:16 http://localhost:3000/node_modules/@angular2-material/card/加载资源失败:服务器响应状态为 404(未找到) http://localhost:3000/node_modules/@angular2-material/input/加载资源失败:服务器响应状态为 404(未找到) http://localhost:3000/node_modules/@angular2-material/checkbox /加载资源失败:服务器响应状态为 404(未找到)http://localhost:3000/node_modules/@angular2-material/radio/ 加载资源失败:服务器响应状态为 404(未找到找到) http://localhost:3000/node_modules/@angular2-material/icon/加载资源失败:服务器响应状态为404(未找到) http://localhost:3000/node_modules/@angular2-material /list/加载资源失败:服务器响应状态为 404(未找到) http://localhost:3000/favicon.ico加载资源失败:服务器响应状态为 404(未找到)