Angular不是已知元素:在同一模块中

Angular不是已知元素:在同一模块中,angular,Angular,我有一个角模,它有两个分量 第一个组件的定义如下 概述.组件.ts @Component({ selector: 'app-pricing-table', templateUrl: './pricing-table.component.html', styleUrls: ['./pricing-table.component.scss'] }) export class PricingTableComponent implements OnInit { } 在第二个组件中,我尝试使

我有一个角模,它有两个分量

第一个组件的定义如下

概述.组件.ts

@Component({
  selector: 'app-pricing-table',
  templateUrl: './pricing-table.component.html',
  styleUrls: ['./pricing-table.component.scss']
})
export class PricingTableComponent implements OnInit {
}
在第二个组件中,我尝试使用给定的标记包含overview组件

<app-pricing-table></app-pricing-table>
当我运行
ng serve
时,我得到一个错误。我已多次重新启动开发服务器

ERROR in src/app/modules/subscription/pages/overview/overview.component.html:13:1 - error NG8001: 'app-pricing-table' is not a known element:
1. If 'app-pricing-table' is an Angular component, then verify that it is part of this module.
2. If 'app-pricing-table' is a Web Component then add 'CUSTOM_ELEMENTS_SCHEMA' to the '@NgModule.schemas' of this component to suppress this message.

13 <app-pricing-table></app-pricing-table>

  src/app/modules/subscription/pages/overview/overview.component.ts:5:16
    5   templateUrl: './overview.component.html',
    Error occurs in the template of component OverviewComponent.
和我的
app.module.ts

{
   path: 'subscription',
   loadChildren: () => import('./modules/subscription/subscription-routing.module').then(m => m.SubscriptionRoutingModule),
}
@NgModule({
  declarations: [
    AppComponent,
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,
    CollapseModule,
    HttpClientModule,
    BsDropdownModule.forRoot(),
    ToastrModule.forRoot()
  ],
  providers: [
    { provide: 'API_ENDPOINT', useValue: environment.apiEndpoint },
    { provide: HTTP_INTERCEPTORS, useClass: ApiEndpointInterceptor, multi: true }
  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

您必须从已创建的模块中导出组件,并在导出中提及它们:[]

  exports: [
    OverviewComponent,
    PricingTableComponent,
  ]
将“提供者”添加到延迟加载的SubscriptionRoutingModule:

@NgModule({
  declarations: [OverviewComponent, PricingTableComponent],
  ...
  providers: [OverviewComponent,PricingTableComponent]
})
export class SubscriptionRoutingModule { }

这就是SubscriptionModule中的全部内容?能否发布OverviewComponent.htmlies的代码,而不是其他导入、导出、,声明或提供程序。@Sajeetharan概览html只包含
标记。您是否已在
AppModule
中导入
SubscriptionModule
?我
已将这两个组件添加到
exports`数组中,但仍然收到相同的错误。(开发服务器重新启动)@Markus,然后您是否在app.module.tsI中正确导入此模块在app routing中使用延迟加载导入它
loadChildren:()=>import('./modules/subscription/subscription routing.module')。然后(m=>m.SubscriptionRoutingModule),
谢谢Marc!你让我开心:)
@NgModule({
  declarations: [OverviewComponent, PricingTableComponent],
  ...
  providers: [OverviewComponent,PricingTableComponent]
})
export class SubscriptionRoutingModule { }