2016-09-18 24 views
1

注意:我不使用角CLI如何使用angular2,快速啓動應用程序angular2材料(阿爾法8.2)整合

這plunker正在與α-8.1https://plnkr.co/edit/qoZ3YCwSz0mQ5o974Dt0?p=preview


我有我的快速入門應用程序運行沒有任何問題。

步驟1:我更新的package.json包括angular2材料angular2按鈕包。

的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" 
    } 
} 

步驟2:我跑NPM安裝,我可以看到@角材料文件夾下node_modules文件夾。


步驟3:更新systemjs.config.js映射@ angular2 /材料node_modulesumd.js文件。

注意我有應用: 'DIST'.TS分離.map.js的.js文件文件

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 (…)

+1

您確定您的'node_modules/@ angular2-material/button/button.umd.js'路徑是否存在?你也有一個錯字'<按鈕md-button-raised>按鈕'。它應該是''我在你的'AppModule'中看到雙重輸入' – yurzui

+0

只是片刻,讓我檢查一下。 – micronyks

+0

是的一切都是按照說的。 – micronyks

回答

1

注意集成angular2材料與核心angular2應用,不與Angular2-CLI。

我有一個小的錯字,糾正它,所以現在一切正常。

注意:那些誰在整合Angular2材料核心Angular2應用面臨一些障礙,可以按照問題本身建議的步驟。

我已經問過這個問題兩次與早期版本,但沒有任何工作。

但最後,按照問題所示的步驟,你將能夠使用angular2材料核心angular2應用

0

我有更多的解決辦法,允許您使用按鈕和東西,而在systemjs.config.js文件分別導入試

第1步:創建的package.json文件

{ 
    "name": "fist-angular-app", 
    "version": "1.0.0", 
    "author": "any name you want", 
    "description": "this is the first angular app", 
    "scripts": { 
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ", 
    "tsc": "tsc", 
    "tsc:w": "tsc -w", 
    "lint": "tslint ./app/**/*.ts -t verbose", 
    "lite": "lite-server", 
    "typings": "typings", 
    "postinstall": "typings install" 
    }, 
    "license": "ISC", 
    "dependencies": { 
    "@angular/common": "2.2.0", 
    "@angular/compiler": "2.2.0", 
    "@angular/core": "2.2.0", 
    "@angular/forms": "2.2.0", 
    "@angular/http": "2.2.0", 
    "@angular/platform-browser": "2.2.0", 
    "@angular/platform-browser-dynamic": "2.2.0", 
    "@angular/router": "3.0.0", 
    "angular-material": "^1.1.1", 

    "bootstrap": "^3.3.6", 
    "core-js": "^2.4.1", 
    "hammerjs": "^2.0.8", 
    "jquery": "^3.1.1", 
    "reflect-metadata": "^0.1.3", 
    "rxjs": "5.0.0-beta.12", 
    "systemjs": "0.19.27", 
    "zone.js": "^0.6.23" 
    }, 
    "devDependencies": { 
    "@types/hammerjs": "^2.0.33", 
    "concurrently": "^2.2.0", 
    "lite-server": "^2.2.0", 
    "tslint": "^3.7.4", 
    "typescript": "^2.0.2", 
    "typings": "^1.0.4" 
    }, 
    "repository": {} 
} 

第2步:使用NPM命令NPM安裝

第3步:鉻eate systemjs.config.js文件

步驟4:

/** 
* System configuration for Angular 2 samples 
* Adjust as necessary for your application needs. 
*/ 
(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: 'app', 

     // angular bundles 
     '@angular/core': 'npm:@angular/core/bundles/core.umd.js', 
     '@angular/common': 'npm:@angular/common/bundles/common.umd.js', 
     '@angular/compiler': 'npm:@angular/compiler/bundles/compiler.umd.js', 
     '@angular/platform-browser': 'npm:@angular/platform-browser/bundles/platform-browser.umd.js', 
     '@angular/platform-browser-dynamic': 'npm:@angular/platform-browser-dynamic/bundles/platform-browser-dynamic.umd.js', 
     '@angular/http': 'npm:@angular/http/bundles/http.umd.js', 
     '@angular/router': 'npm:@angular/router/bundles/router.umd.js', 
     '@angular/forms': 'npm:@angular/forms/bundles/forms.umd.js', 
     '@angular/material': 'npm:@angular/material/material.umd.js', 

     // other libraries 
     'rxjs': 'npm:rxjs' 
    }, 
    // 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' 
     } 
    } 
    }); 
})(this); 

步驟5:使用NPM命令NPM安裝@角/材料

步驟6:下面添加在應用.module。TS文件

import { NgModule } from '@angular/core'; 
import { FormsModule } from '@angular/forms'; 
import { MaterialModule } from '@angular/material'; 

@NgModule({ 
    imports: [ 
     FormsModule, 
     MaterialModule.forRoot(), 
     ]) 
export class AppModule { } 

步驟7:檢查下面的文件夾在項目

  1. node_modules
  2. node_module/@ angulae /材料
  3. node_modules /角材料
  4. 分型(如果不是可用用途npm)

它會開始工作