Angular 确认它是此模块的一部分

Angular 确认它是此模块的一部分,angular,Angular,我认为我不太理解组件声明在Angular中是如何工作的。我有两个模块App和Navigation,在NavigationModule中我有几个组件,导航下划线和导航栏。当我尝试在导航栏组件中使用导航下划线时,我得到验证它是否是此模块的一部分。错误 下面是下面的代码 @NgModule({ imports: [ CommonModule ], declarations: [NavigationBarComponent, NavigationUnderlineComponent]

我认为我不太理解组件声明在Angular中是如何工作的。我有两个模块
App
Navigation
,在NavigationModule中我有几个组件,
导航下划线
导航栏
。当我尝试在
导航栏
组件中使用
导航下划线
时,我得到
验证它是否是此模块的一部分。
错误

下面是下面的代码

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [NavigationBarComponent, NavigationUnderlineComponent]
})
export class NavigationModule { }


## navigation-bar.html
<a style="font-size: 6em;" routerLink="/">Blah Blah</a>
<nav>
  <a routerLink="/">ABOUT</a>
  <a routerLink="/">RESUME</a>
</nav>
<app-navigation-underline></app-navigation-underline>
@NgModule({
进口:[
公共模块
],
声明:[NavigationBarComponent,NavigationUnderlineComponent]
})
导出类导航模块{}
##navigation-bar.html
废话
关于
简历
我还试图在app模块中声明它,但它不起作用,我也不需要这样做,因为我只在导航模块中使用
。不知道我为什么会出错

编辑:好吧,我似乎已经解决了这个问题,我在导航模块中导出了
NavigationUnderlineComponent
,然后在
AppModule
中导入了它,但我不太明白为什么需要它


EDIT2:实际上我甚至不需要导出它,我只需要在AppModule中声明它。为什么我需要在应用程序模块中声明此组件?

好的,我找到了

我真正想做的是只在NavigationModule上下文中使用导航下划线。我是通过以下方式实现的

@NgModule({
  imports: [
    CommonModule
  ],
  declarations: [NavigationBarComponent, NavigationUnderlineComponent],
  exports: [NavigationBarComponent]
})
export class NavigationModule { }
请注意,NavigationUnderlineComponent未导出。然后在AppModule中

@NgModule({
  declarations: [
    AppComponent,
    BlogIndexComponent,
    BlogPreviewCardComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    NavigationModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }
这允许我将导航下划线限制为仅在NavigationModule中使用