代码之家  ›  专栏  ›  技术社区  ›  Lapenkov Vladimir

以一个模块的组件作为应用程序模块路由中的路径

  •  0
  • Lapenkov Vladimir  · 技术社区  · 7 年前

    我有一个简单的模块,另一个模块,我想它是 反成分 在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错误

    1 回复  |  直到 7 年前
        1
  •  1
  •   Adrien SAULNIER    7 年前

    在你的 AppModule ,删除 CounterComponent declarations 模块属性。他已经在 SomeOtherModule .

    编辑:我不知道你是不是为这个问题删掉了,但如果不是,你忘了导入。 反成分 在你的 应用程序模块 文件夹。

    推荐文章