NOTE: I don't use Angular-CLI
这个plunker正在使用 Alpha-8.1 : https://plnkr.co/edit/qoZ3YCwSz0mQ5o974Dt0?p=preview
我的快速启动应用程序运行没有任何问题 .
Step 1 :我更新了 package.json 以包含 angular2-material 和 angular2-button 包 .
package.json
{
"name": "angular2-quickstart",
"version": "1.0.0",
"scripts": {
"start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" ",
"lite": "lite-server",
...
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0",
"@angular/compiler": "2.0.0",
"@angular/core": "2.0.0",
"systemjs": "0.19.27",
...
...
//<<<<<<<<<<<<<<<<<<<<<Here>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
"@angular2-material/core":"2.0.0-alpha.8-2",
"@angular2-material/button ":"2.0.0-alpha.8-2"
//<<<<<<<<<<<<<<<<<<<<<Here>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
},
"devDependencies": {
"concurrently": "^2.2.0",
"lite-server": "^2.2.2",
"typescript": "^2.0.2",
"typings":"^1.3.2"
}
}
Step 2 :我跑了 npm install ,我可以在 node_modules 文件夹下看到 @angular-material 文件夹 .
Step 3 :更新了 systemjs.config.js 以将 @angular2/material 包映射到 node_modules umd.js 文件 .
NOTE :我有 app: 'dist' 将 .map.js 和 .js 文件与 .ts 文件分开
systemjs.config.js
(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: 'dist',
// angular bundles
'@angular/core': 'npm:@angular/core/bundles/core.umd.js',
'@angular/common': 'npm:@angular/common/bundles/common.umd.js',
...
...
//<<<<<<<<<<<<<<<<<<<<<Here>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
'@angular2-material/core': 'npm:@angular2-material/core/core.umd.js',
'@angular2-material/button': 'npm:@angular2-material/button/button.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'
},
'angular2-in-memory-web-api': {
main: './index.js',
defaultExtension: 'js'
}
}
});
})(this);
Step 4 :更新了 app.module.ts
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import { MdButtonModule } from '@angular2-material/button';
//import { MdCardModule } from '@angular2-material/card';
@NgModule({
imports: [ BrowserModule,MdButtonModule ],
declarations: [ AppComponent ],
bootstrap: [ AppComponent ]
})
export class AppModule { }
Step 5 :更新了 app.component.ts
import { Component } from '@angular/core';
import { MD_BUTTON_DIRECTIVES } from '@angular2-material/button';
@Component({
selector: 'my-app',
template: `<h1>My First Angular 2 App Live</h1>
<button md-raised-button>Button</button>
`
})
export class AppComponent { }
Error :
localhost /:16错误:错误:XHR错误(404 Not Found)loading http:// localhost:3000/node_modules/@angular2-material/button/button.umd.js(...)
2 回答
NOTE : integration of angular2-material with core angular2 app, not with Angular2-CLI.
我有一个小错字,纠正它所以现在一切正常 .
NOTE :那些在将 Angular2-material 与 core Angular2 app 整合时面临一些障碍的人可以按照本身提出的步骤进行操作 .
我早先的版本已经问过这个问题 two times ,但没有任何效果 .
但最后,按照以下步骤进行操作, you will be able to use angular2-material with core angular2 app.
我尝试了更多的解决方法,允许您使用按钮和东西,而无需在systemjs.config.js文件中单独导入
Step 1: 创建package.json文件
Step 2: 使用npm命令npm install
Step 3: 创建systemjs.config.js文件
Step 4:
Step 5: 使用npm命令npm install @ angular / material
Step 6: 在app.module.ts文件中添加以下内容
Step 7: 检查项目中的下方文件夹
node_modules
node_module / @ angulae / material
node_modules / angular-material
打字(如果不可用,请使用npm)
它将开始工作