방법

2017-04-19 4 views
0
각도

에서 루트 구성 요소를 감지하는 I 다음이 개 내 app.module.ts에서 루트가 내 app.component.html에서방법

const appRoutes: Routes = [ 
     {path: 'property/:id', component: PropertyDetailComponent}, 
     { 
     path: 'properties', 
     component: ListingViewComponent, 
     data: { title: 'Properties List' } 
     }, 
     { path: '', 
     redirectTo: '/properties', 
     pathMatch: 'full' 
     } 
    ]; 

을 내가 가지고있는 다음과 같은 구성 요소와 출구 :

<side-nav></side-nav> 

<contact-agent></contact-agent> 

<router-outlet></router-outlet> 

PropertyView에 대한 사이드 탐색과 PropertyDetail에 대한 contact-agent를 표시하려고합니다.

어떻게 조건부로 표시 할 수 있습니까? 경로에서 data/title 속성을 사용합니까? 당신은 사이드 탐색을위한 보조 (또한 보조) 경로를 정의 고려하고 연락 에이전트를 할 수 있습니다

<div *ngIf="title === 'Properties List'"> 
<contact-agent></contact-agent> 
</div> 

답변

2

: 같은

뭔가. 그런 다음 보조 콘센트의 해당 콘텐트로 라우팅 할 수 있습니다. https://angular.io/docs/ts/latest/guide/router.html#!#secondary-routes

을하지만 기본적으로 HTML은 다음과 같을 것이다 :

여기에 대한 자세한 보조 경로를 찾을 수 있습니다

<router-outlet name=secondaryInfo></router-outlet> 
<router-outlet></router-outlet> 
+0

감사합니다. 구성 요소는 어떻게 생겼을까요? – Atma

+0

경로 활성화 코드를 묻는 중입니까? 여기에 코드 예제가 있습니다. https://github.com/DeborahK/Angular-Routing this.router.navigate ([{outlets : {popup : [ 'messages']}}]); 여기서 popup은 보조 콘센트의 이름이고 메시지는 경로입니다. – DeborahK