注意:我不使用 Angular-CLI
这个 plunker 正在使用Alpha-8.1:https ://plnkr.co/edit/qoZ3YCwSz0mQ5o974Dt0?p=preview
我的快速启动应用程序正在运行,没有任何问题。
第 1 步:我更新了package.json以包含angular2-material和angular2-button包。
包.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"
}
}
第 2 步:我运行npm install,我可以在node_modules文件夹下看到@angular-material文件夹。
第 3 步:更新systemjs.config.js以将@angular2/material包映射到node_modules umd.js文件。
注意:我有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);
第 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 { }
第 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 { }
错误:
localhost/:16 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular2-material/button/button.umd.js (...)