2017-03-01 5 views
0

라우터 출력이있는 구성 요소가 있습니다. 이 구성 요소에는 서비스를 통해 ngOnInit의 일부 범주로 피드하는 select 요소가 있습니다. 3 개의 자식 경로가 있으며 그 중 하나는 해당 범주를 사용하려는 구성 요소로 이동합니다.각도 2 : 부모와 자식 간의 데이터 전송

내 노선이 2 HTTP이 범주를 얻기 위해 호출하고있다이

const routes: Routes = [ 
{ 
    path: 'marketplace', 
    component: MarketplaceComponent, 
    resolve: { categories: CategoriesResolveService }, 
    canActivate: [AuthenticatedGuard], 
    children: [  
    { path: 'modules', component: ModulesComponent, resolve: { categories: CategoriesResolveService } }  
    ] 
}]; 

처럼 보인다. 이 데이터를 하위 구성 요소로 전송하려면 어떻게해야합니까? 다른 http 호출을하지 않으려합니다. 부모와 자녀간에이 데이터를 공유 할 수 있습니까?

+0

도움이 될()? –

+0

viewChild가 어떤 것인지 잘 모르는 경우, 모양이 있습니다. –

+0

ViewChild는 부모 구성 요소에 선언 된 하위 구성 요소를 사용하여 작동합니까? 그렇다면이 시나리오에서는 작동하지 않을 것이라고 생각합니다. 라우터 출력 만 있습니다. –

답변

0
export class parentComponent { 

    @ViewChild(ChildOneComponent) 
    private childOneComponent: ChildOneComponent; 

    @ViewChild(ChildTwoComponent) 
    private childTwoComponent: ChildTwoComponent; 

    let date = this.childOneComponent.method1; 

} 

이 방법 항목은() method.you 당신의 부모 구성 요소의 하위 구성 요소를 가져와야합니다 얻을에 대한 귀하의 하위 구성 요소에서 정의합니다.

ChildOneComponent { 
    get method1() { 
    return this.value//return which value you pass. 
    } 
}