Angular4多个模块问题

Olg*_*ina 7 angular

我有一个应用程序,它有多个视图,如导航和页面.所以我添加了一个布局模块并将该模块导入主模块,现在尝试在app组件中使用布局模块导航组件.所以这应该显示navigation.html内容,但它将变为空白.它也没有给出任何错误.不确定我做错了什么.以下是我的代码,它将提供正确的图片:这是app.model.ts

    

    import { BrowserModule } from '@angular/platform-browser';
    import { NgModule } from '@angular/core';
    import { AppRoutingModule } from './app-routing.module';
    import { AppComponent } from './app.component';
    import { LayoutsModule } from './layouts/index';

    @NgModule({
      declarations: [
        AppComponent
      ],
      imports: [
        BrowserModule,
        LayoutsModule,
        AppRoutingModule
      ],   
      providers: [],
      bootstrap: [AppComponent]
    })
    export class AppModule { }

这是LayoutsModule

   

    import { NgModule } from '@angular/core';
    import { NavigationComponent } from './navigation/navigation.component';


    @NgModule({
      declarations: [
        NavigationComponent
      ],
      exports: [

      ],
      imports: [

      ],
      providers: [

      ]
    })
    export class LayoutsModule {}

和我的app.component.html

 

    <app-navigation></app-navigation>
    <router-outlet></router-outlet>

Pan*_*kar 5

您应该NavigationComponent从自己导出,LayoutsModule以便可以使用LayoutsModule。基本上,不管你想要接触到由内而外角另一个模块/系统中,你必须把那些component/ directive/ pipe里面exports的元数据方案NgModule或相反,它可能已经通过加载route从角路由器网段。

@NgModule({
  declarations: [
    NavigationComponent
  ],
  exports: [
      NavigationComponent
  ],
  imports: [],
  providers: []
})
export class LayoutsModule {}
Run Code Online (Sandbox Code Playgroud)

不知道为什么您没有收到错误消息。它应该抛出一个错误。