【发布时间】:2016-04-05 21:37:47
【问题描述】:
应用组件:
@RouteConfig([
{path:'/', name: 'Dashboard', component: DashboardComponent, useAsDefault: true},
{path:'/model/:id', name: 'ModelDetail', component: ModelDetailComponent},
])
访问者直接访问: http://localhost:8080/model/4
在渲染“ModelDetailComponent”之前,我们需要在 ngOnInit() 类中加载所有模型。
ngOnInit() {
let id = parseInt(this.routeParams.get('id'));
this.modelService.subject$.subscribe(models => {
if ( models.length > 0 ) {
this.model = models[0];
}
})
this.modelService.getModel(id);
}
模板:
<h1>{{model.name}}</h1>
<model-list [model]="model"></model-list> //nested compnent that also use the model.
财产
public model:IModel;
【问题讨论】: