注意:我不使用Angular Cli .
我添加了 @angular2-material/core 包 . 然后我安装了其他angular2材料组件,如 @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(未找到)localhost /:16错误:错误:XHR错误(找不到404) )加载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-mate rial / 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(未找到)
3 回答
您应该在
system-config.ts
中根据需要单独添加材料组件:1. angular-cli以dist /目录为目标
并在
angular-cli-build.js
:2. lite-server或http-server目标应用程序根目录
这是来自角度材料2的来源
system.config.ts
:material2/GETTING_STARTED.md
npm
plunker
npm i @angular2-material/core --save
npm i @angular2-material/card --save
npm i @angular2-material/toolbar --save
npm i @angular2-material/button --save
npm i @angular2-material/slide-toggle --save
适用于:Angular 2 QuickStart Source
零件:
系统配置:
请将@ angular2 RC4更新为RC5并添加如下配置文件