【问题标题】:Didn't recognise Material import in child modules angular 2无法识别子模块 angular 2 中的材料导入
【发布时间】:2018-06-29 00:54:52
【问题描述】:

我有 app.module.ts 如何导入自定义 material.ts 模块,但我不能在模块根目录中声明的组件中使用材料。但是当我创建一个子模块(ClientModule)并在这里声明一个组件时,无法识别材料。

@NgModule({
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    LayoutModule,
    MaterialModule,
    ReactiveFormsModule,
    HttpModule,
    ClientModule
  ],
  declarations: [
    AppComponent,
    NavigatorComponent,
    LoginComponent,
  ],
  providers: [AuthService],
  bootstrap: [AppComponent]
})
export class AppModule { }

ClientRegistrationComponent 不能使用角度材质,我也应该导入材质模块吗?

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { ClientRegistrationComponent } from './client-registration/client-registration.component';

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [ClientRegistrationComponent]
})
export class ClientModule { }

【问题讨论】:

  • 请添加更多详细信息,哪个模块不起作用并发布相关代码
  • 抱歉,已添加代码 :)

标签: angular angular-material


【解决方案1】:

要在您的应用程序中使用 MaterialModule,我建议您创建一个 SharedModule 并在所有模块中导入 SharedModule。

如果你不想要 SharedModule,是的,在上述情况下你需要导入

【讨论】:

  • 好吧,当我在应用程序模块(根)中导入我的材料模块时。不是所有其他组件都可以使用吗?
  • 不能只使用模块内的组件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-11
  • 1970-01-01
  • 1970-01-01
  • 2020-06-14
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多