Angular Material 配置错误和警告请帮我弄清楚

标签 angular angular-material

使用 cli 的 Angular Material 2。当我安装 @angular/material 并将其包含在 app.module 中时,编译器会收到 3 个警告。

我做了什么

npm install --save @angular/material

其他进口

import { MaterialModule } from '@angular/material';

@NgModule({

  declarations: [
    AppComponent
  ],

  imports: [
    MaterialModule.forRoot(),other imports...
  ],

  providers: [],
  bootstrap: [AppComponent]
})

export class AppModule { }

其他设置

样式.css

@import '~@angular/material/core/theming/prebuilt/deeppurple-amber.css';

index.html

    <script src="https://ajax.googleapis.com/ajax/libs/hammerjs/2.0.8/hammer.min.js"></script>
    <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

警告

1. WARNING in ./~/@angular/material/module.js
64:4 export 'ProjectionModule' was not foun
d in './core/index'
 2. WARNING in ./~/@angular/material/module.js
89:16 export 'ProjectionModule' was not fou
nd in './core/index'
 3. WARNING in ./~/@angular/material/dialog/ind
ex.js
21:75 export 'Platform' was not found in '.
./core'

运行错误 http://localhost:4200/

Uncaught TypeError: Cannot read property 'prototype' of undefined
    at __extends (snack-bar-container.js:4)
    at snack-bar-container.js:28
    at Object.<anonymous> (snack-bar-container.js:122)
    at __webpack_require__ (bootstrap 9ff6af8…:52)
    at Object.<anonymous> (snack-bar-ref.js:70)
    at __webpack_require__ (bootstrap 9ff6af8…:52)
    at Object.<anonymous> (menu.js:40)
    at __webpack_require__ (bootstrap 9ff6af8…:52)
    at Object.<anonymous> (icon.js:264)
    at __webpack_require__ (bootstrap 9ff6af8…:52)

最佳答案

来自官方documentation ,您应该导入每个模块。我在开发过程中一次导入所有内容,但没有 .forRoot(),并且工作正常:

 imports: [
    MaterialModule,
  ],

关于 Angular Material 配置错误和警告请帮我弄清楚,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41374707/

相关文章:

angular - 在 Angular 2 的 rxjs 中使用 switchMap 运算符时,我们是否必须取消订阅?

Angular2,如何清除路由器导航上的 URL 查询参数

javascript - Angular 更改 JSON 键名称

javascript - 无法在 Angular Material 日期选择器中设置日期

css - Angular Material 列表设计

javascript - Angular <base href ="./path"> 忽略静态资源

javascript - 在单击任何对象之前,Angular 2 不会更新

angular - 如何在 Angular 中使用 mat-text-column

angular - 如何更改表中值的格式?

javascript - 使用 Angular Material 步进器在输入类型文本中添加自定义验证