【发布时间】:2016-04-27 20:20:56
【问题描述】:
我需要从子路由视图设置标题标题...
我有父组件:
@Component({
selector: 'parent-component',
template: `
<header>{{headerTitle}}</header>
<router-outlet></router-outlet>
`,
directives: [ROUTER_DIRECTIVES]
})
@RouteConfig([
{ path: '/link1', name: 'Link1', component: Link1Component, useAsDefault: true },
{ path: '/link2', name: 'Link2', component: Link2Component },
])
export class ParentComponent {
public sharedHeaderTitle: string;
constructor(public router: Router) { }
}
有一个子路由标签:
@Component({
template: '<div></div>'
})
export class Link1Component {
public headerTitle: string;
constructor() {
this.headerTitle = "Link1 page";
}
}
还有一个
@Component({
template: '<div></div>'
})
export class Link2Component {
public headerTitle: string;
constructor() {
this.headerTitle = "Link2 page";
}
}
我找到了here,但它不能用于路由...
最好的制作方法是什么?
已解决
我找到了一种解决方案,认为这是最好的方法:
http://plnkr.co/edit/LYTXmY9Fwm8LwumICWDT
【问题讨论】: