【问题标题】:Can I use Angular Material 2.0.0-alpha.9-3 with angular 2.1?我可以将 Angular Material 2.0.0-alpha.9-3 与 Angular 2.1 一起使用吗?
【发布时间】:2017-02-22 12:37:15
【问题描述】:

我尝试在 Angular 2.1 中使用 angular/material ^2.0.0-alpha.9-3,但出现异常:

zone.js:1274 GET http://localhost:3000/@angular/material 404(未找到)

(index):16 错误: (SystemJS) XHR 错误 (404 Not Found) loading http://localhost:3000/@angular/material(...)

我刚刚使用“Angular2 快速入门”上的说明创建了项目并运行命令:“npm install --save @angular/material”。在此命令之后,添加了 node_modules/@angular 中的文件夹“material”。

我的 package.json 是:

{
  "name": "user-manager",
  "version": "1.0.0",
  "scripts": {
    "start": "tsc && concurrently \"tsc -w\" \"lite-server\" ",
    "lite": "lite-server",
    "postinstall": "typings install",
    "tsc": "tsc",
    "tsc:w": "tsc -w",
    "typings": "typings"
  },
  "licenses": [
    {
      "type": "MIT",
      "url": "https://github.com/angular/angular.io/blob/master/LICENSE"
    }
  ],
  "dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.0",
    "@angular/material": "^2.0.0-alpha.9-3",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@angular/upgrade": "~2.1.0",
    "angular-in-memory-web-api": "~0.1.5",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "zone.js": "^0.6.25"
  },
  "devDependencies": {
    "concurrently": "^3.0.0",
    "lite-server": "^2.2.2",
    "typescript": "^2.0.3",
    "typings": "^1.4.0"
  }
}

app.module.ts:

import { NgModule }      from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { AppComponent }   from './components/app/app.component';
import { MaterialModule } from '@angular/material';

@NgModule({
    imports:      [ BrowserModule, MaterialModule.forRoot() ],
    declarations: [ AppComponent ],
    bootstrap:    [ AppComponent ]
})
export class AppModule { }

你能帮帮我吗?

【问题讨论】:

    标签: angular angular-material


    【解决方案1】:

    更新

    从 2.0.0-beta.1 rebar-teacup 开始

    '@angular/material': 'npm:@angular/material/bundles/material.umd.js'
    

    以前的版本

    更改您的 systemjs 配置,如:

    map: {
      app: 'app',
      '@angular/core': 'npm:@angular/core/bundles/core.umd.js',
      ...
      '@angular/material': 'npm:@angular/material/material.umd.js', <== add this line
    },
    

    另见Angular2 Material Design alpha.9-3 has '404 not found' for @angular/material

    【讨论】:

      猜你喜欢
      • 2017-05-20
      • 1970-01-01
      • 1970-01-01
      • 2018-01-11
      • 2018-04-20
      • 2014-03-24
      • 2017-09-28
      • 2020-12-16
      • 1970-01-01
      相关资源
      最近更新 更多