【发布时间】:2016-03-25 15:29:07
【问题描述】:
我的页面中有一个子导航,它在公共主视图下方显示一些子视图。我想通过<router-outlet> 将一个对象传递给子视图,以便我可以在主组件中检索一次数据并与我的子组件共享。
注意:如果我在 main.html 中包含指令 <one></one>,它会起作用,但这不是我想要的行为。
主视图:
<h1>Details</h1>
<a [router-link]="['./sub1']">One</a> |
<a [router-link]="['./sub2']">Two</a> |
<a [router-link]="['./sub3']">Three</a>
<hr/>
<router-outlet [data]="maindata"></router-outlet>
子视图 1:
<h2>{{ data.name }}</h2>
...
主视图:
@Component({
selector: 'main-detail',
directives: [ROUTER_DIRECTIVES],
templateUrl: './main.html'
})
@RouteConfig([
{ path: '/', redirectTo: '/one' },
{ path: '/one', as: 'One', component: OneComponent },
{ path: '/two', as: 'Two', component: TwoComponent },
{ path: '/three', as: 'Three', component: ThreeComponent }
])
export class MainComponent {
maindata: Object = {name:'jim'};
}
子视图 1:
@Component({
selector: 'one',
directives: [CORE_DIRECTIVES],
inputs: ['data'],
templateUrl: './one.html'
})
export class OneComponent {
@Input() data;
}
【问题讨论】:
-
查看issue
标签: typescript angular angular2-template