我有简单的模块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 { }
和AppModule:
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 },
]
)]
未找到CounterComponent时出现TS错误
答案 0 :(得分:1)
在AppModule
中,从CounterComponent
模块属性中删除declarations
。他已经在SomeOtherModule
宣布了。
编辑:我不知道您是否针对该问题进行了剪切,但如果没有,则忘记在CounterComponent
文件中导入AppModule
。