我试着用home-itens.component中的side-bar.component,但出于某种原因,它说'app-side-bar' is not a known element

Home-itens.module:

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SideBarModule } from './../side-bar/side-bar.module';
import { HomeItensRoutingModule } from './home-itens-routing.module';

@NgModule({
imports: [
   CommonModule,
   HomeItensRoutingModule,
   SideBarModule
  ],
})
export class HomeItensModule { }

侧栏.模块:

import { NgModule } from '@angular/core';
import { RouterModule } from '@angular/router';
import { CommonModule } from '@angular/common';
import { PoModule } from '@po-ui/ng-components';
import { SideBarComponent } from './side-bar.component';
import { PoMenuPanelModule } from '@po-ui/ng-components';

@NgModule({
  declarations: [
     SideBarComponent
  ],
  imports: [
    PoModule,
    CommonModule,
    RouterModule,
    PoMenuPanelModule,
 ],
 exports:[
   SideBarComponent
 ]
 })
export class SideBarModule {}

推荐答案

我创造了一个working stackblitz here.

  1. side-bar.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { SideBarComponent } from './side-bar.component';

@NgModule({
  imports: [CommonModule],

  // add the 'SideBarComponent' to the module declaration
  declarations: [SideBarComponent], 

  // export the 'SideBarComponent' for use by other components and modules, 
  // and in this case the 'HomeItemsModule'
  exports: [SideBarComponent], 
})
export class SideBarModule {}

  1. home-items.module.ts
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { HomeItemsComponent } from './home-items.component';
import { SideBarModule } from '../side-bar/side-bar.module';

@NgModule({
  //import the 'SideBarModule': it contains the 'SideBarComponent'
  imports: [CommonModule, SideBarModule], 

  // add the 'HomeItemsComponent' to your module declaration
  declarations: [HomeItemsComponent],

  exports: [HomeItemsComponent],
})
export class HomeItemsModule {}

  1. app.module.ts

import { AppComponent } from './app.component';
import { HomeItemsModule } from './home-items/home-items.module';

@NgModule({
  // import the 'HomeItemsModule' here. Recall that it already includes the    
  // 'SideBarModule' so we do not need to import it again
  imports: [BrowserModule, FormsModule, SideBarModule,HomeItemsModule],
  declarations: [AppComponent],
  bootstrap: [AppComponent],
})
export class AppModule {}

Angular相关问答推荐

Angular v12:Uncatch(in promise):ReferenceError:d3 is not defined ReferenceError:d3 is not defined

Toastr在独立组件上的Angular17实现

Angular 如何观察DOM元素属性的变化?

具有多个输入的Angular struct 指令在第一次加载构件时没有值

ANGLING:ExpressionChangedAfterChecked在嵌套形式中由子项添加验证器

使用 TAB 键时如何聚焦mat-select组件?

使用 Angular 类构造函数来获取依赖项

无法创建新的 Ionic 项目

如何在独立组件中导入Angular innerHTML

Nz 树 Select .如何在子 node 中显示父 node 名称?

Angular JWT Token 被添加到lazyUpdate 而不是 HttpHeaders 中的标头

Angular 从 13.3.8 恢复到 13.3.7

多个 Mat Paginator 在 Angular 组件中不起作用

在 Angular2 中跟踪 Google Analytics 页面浏览量

material Angular手风琴header/title高度

Angular 2如何让子组件等待异步数据准备好

在 Angular 2 中打印 Html 模板

交替行 colored颜色 angular material表

angular2 测试,我如何模拟子组件

输入更改时Angular2动态输入字段失go 焦点