使用一个模块的组件作为应用模块路由中的路径



我有一个简单的模块SomeOtherModule,我希望它的CounterComponent可以作为AppModule中的路径。

import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { CounterService } from '../services/counter.service';
import { CounterComponent } from '../counter/counter.component';
@NgModule({  
imports: [ CommonModule],
providers: [CounterService],
declarations: [  CounterComponent ],
exports: [CounterComponent] 
})
export class SomeOtherModule { }

和应用模块:

import { SomeOtherModule } from './some-other/some-other.module';
@NgModule({
declarations: [
AppComponent,  
HomeComponent,     
CounterComponent, 
],
imports: [SomeOtherModule,
RouterModule.forRoot([
{ path: '', component: HomeComponent, pathMatch: 'full' },
{ path: 'counter', component: CounterComponent }, 
]
)]

在计数器组件上找不到 TS 错误

AppModule中,从模块属性中删除CounterComponentdeclarations。他已经在SomeOtherModule上宣布了.

编辑:我不知道你是否为这个问题削减了它,但如果没有,你忘了在你的AppModule文件中导入CounterComponent

最新更新