如何为angular 2项目添加物化?

时间:2017-11-17 16:47:19

标签: angularjs angular2-template angular-material2

我正在从这个项目的角度1.5移动到角度2,同时设置新的应用程序我来到这个问题所以我将这个库添加到应用程序。 https://www.npmjs.com/package/angular2-materialize但是这个错误导致此库不兼容。我想使用支持角度2的角度物化。任何更好的源或如何使用上面的库实现。

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { HttpModule } from '@angular/http';
import { RouterModule } from '@angular/router';
import { AppComponent } from './app.component';
import { StreamComponent } from './stream/stream.component';
import { StreamService } from './stream.service';
import { routing } from './app.routes';
import { MaterializeModule } from "angular2-materialize";
const ROUTES = [
  {
    path: '',
    redirectTo: 'app',
    pathMatch: 'full'
  },
  {
    path: 'stream',
    component: StreamComponent
  }
];

@NgModule({
  declarations: [
    AppComponent,
    StreamComponent
  ],
  imports: [
    BrowserModule,
    FormsModule,
    HttpModule,
    routing,
    MaterializeModule
  ],
  providers: [StreamService],
  bootstrap: [AppComponent]
})
export class AppModule { }

ERROR

angular-material.js:13 Uncaught TypeError: Cannot read property 'module' of undefined
    at angular-material.js:13
    at angular-material.js:14
    at angular-material.js:36390
(anonymous) @ angular-material.js:13
(anonymous) @ angular-material.js:14
(anonymous) @ angular-material.js:36390
index.js:4 Uncaught ZoneAwareError {__zone_symbol__error: Error: Couldn't find Materialize object on window. It is created by the materialize-css library. Ple…, …}

1 个答案:

答案 0 :(得分:0)

要导入实体化,您需要在代码中添加import语句

import { MaterializeModule } from "angular2-materialize";

并在导入后声明它

@NgModule({
  imports: [
  //...
    MaterializeModule,
  ],
  //...
})

我想在你的情况下导入问题,尝试在路由之前声明MaterializeModule。如果它没有帮助请提供错误消息