2016-11-07 2 views
0

나는 앵귤러 2 어플리케이션을 구축하려고 시도해 왔습니다. 이 기본 구조가 있습니다.중첩 모듈에서 라우팅 지정 NPM 패키지를 통한 각도 2

AppModule

  • AppComponent
  • App.Routing
  • App.template
  • App.module

나는 다른 모듈의이 NPM 패키지와 'SampleModule'를 가정 해 봅시다 가지고있는 App.module 파일에서로드 및 가져 오기 중입니다.

이제 내 문제는 'SampleModule'내부의 구성 요소를 가리 키도록 App 라우팅의 경로 중 하나를 지정하는 것입니다. 'SampleComponent'라고 말하면됩니다.

SampleModule에서 구성 요소를 노출 시키려고했는데 여기에 응용 프로그램 라우팅에서 가져 오기를 시도했습니다. 그것은 작동하지 않았다. 그것은 말합니다, SampleComponent라는 이름을 찾을 수 없습니다

어떤 도움을 많이 주시면 감사하겠습니다.

+0

당신은 당신의 코드를 제공 할 수있다?. –

답변

0

'SampleModule'은 npm 패키지이므로 'SampleModule'파일은 node_modules 폴더 (프로젝트 루트 경로) 아래에 있습니다.

먼저 가져 오기 'SampleModule'

import { SampleModule } from '/path_to_node_modules/path_to_sample_module/'; 

@NgModule({ 
    imports: [SampleModule],<== this line 
}) 
export class AppModule{} 

이제 당신이 가져올 수있는 'SampleComponent'직접로 App.module에서 다음

@NgModule({ 
    declarations: [SampleComponet], 
    exports: [SampleComponet] <== this line 
}) 
export class SampleModule{} 

을 SampleModule하려면 다음 행을 추가하여 SampleComponet를 내보낼 귀하의 응용 프로그램 가져 오기 명세서에 따라 다음을 가져 오는 중입니다

import { SampleComponent } from '/path_to_node_modules/path_to_componet/'; 

{ path: 'sample', component: SampleComponent } 

참고 : SampleModule가 자신의 라우팅을 가지고 있으며이

const routes: Routes = [~routings~] 

    @NgModule({ 
     imports: [RouterModule.forChild(routes)], 
     declarations: [SampleComponet], 
     exports: [SampleComponet] <== this line 
    }) 
    export class SampleModule{} 

가 다음 앱 라우터에서 다음 코드를 사용하여 다음과 같이 정의 된 경우

{ 
    path: 'sample', 
    loadChildren: './path_to_node_modules/path_to_sample_module/sample.module#SampleModule' 
}