如何将angular2-material(alpha 8.2)与angular2-Quickstart应用程序集成 [英] How to integrate angular2-material (alpha 8.2) with angular2-Quickstart app

查看:98
本文介绍了如何将angular2-material(alpha 8.2)与angular2-Quickstart应用程序集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意:我不使用Angular-CLI

该监听器正在与 Alpha-8.1 配合使用: https://plnkr.co/edit/qoZ3YCwSz0mQ5o974Dt0?p=preview


我的我的快速启动应用程序正在运行,没有任何问题.

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


第2步:我运行了 npm install ,我可以在 node_modules 文件夹下看到 @ angular-material 文件夹


步骤3 :更新了 systemjs.config.js 以将 @ angular2/material 包映射到 node_modules umd.js 文件.

注意:我有 app:'dist'来分隔 .map.js .js .ts 文件

中的strong>文件

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错误:错误:正在加载XHR错误(找不到404) http://localhost:3000/node_modules/@ angular2-material/button/button.umd.js (…)

解决方案

注意: angular2-material与核心angular2应用(而不是Angular2-CLI)的集成.

我有一个小错字,已改正,所以现在一切正常.

注意:那些将 Angular2-material 核心Angular2应用集成的障碍,可以按照问题本身建议的步骤进行.

对于较早的版本,我已经两次问过这个问题,但没有任何效果.

但是最后,通过执行有问题的步骤,您将可以在 core angular2应用中使用 angular2-material .

NOTE: I don't use Angular-CLI

This plunker is working with Alpha-8.1 : https://plnkr.co/edit/qoZ3YCwSz0mQ5o974Dt0?p=preview


I have my quick-start app running without any issue.

Step 1: I updated package.json to include angular2-material and angular2-button packages.

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: I ran npm install, I could see @angular-material folder under node_modules folder.


Step 3: Updated systemjs.config.js to map @angular2/material package to node_modules umd.js file.

NOTE : I have app: 'dist' to separate .map.js and .js files from .ts files

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: Updated 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: Updated 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 Error: Error: XHR error (404 Not Found) loading http://localhost:3000/node_modules/@angular2-material/button/button.umd.js(…)

解决方案

NOTE: integration of angular2-material with core angular2 app, not with Angular2-CLI.

I had a small typo, corrected it so now everything is working.

NOTE: Those who are facing some hurdles in integrating Angular2-material with core Angular2 app, can follow steps suggested in question itself.

I had already asked this question two times with earlier releases but nothing was working.

But finally, by following steps shown in question, you will be able to use angular2-material with core angular2 app.

这篇关于如何将angular2-material(alpha 8.2)与angular2-Quickstart应用程序集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆