2017-04-19 77 views
0

路由组件我在我的app.module.ts以下2条路线:如何检测角

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

以我app.component.html我有以下组分和出口:

<side-nav></side-nav> 

<contact-agent></contact-agent> 

<router-outlet></router-outlet> 

我想为ListingView和PropertyDetail的contact-agent显示side-nav。

如何有条件地显示这些?我在路线中使用数据/标题属性吗?

喜欢的东西:

<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