:
{ path: 'calculator', component: CalculatorComponent, data: {physical: Physical}},

设置comoponent中的
:
if(this.selectedPhysical) {
this.router.navigate(['/calculator', this.selectedPhysical ]);
}

导航的结果是试图这样做(这显然是错误的):
http://localhost:3000/calculator;pK_Physical=4;fK_Measurement=2;dateString=5/22/2016;weight=270;height=70;hips=27;waist=51;neck=18.5

那么如何将数据传递给路线?
在计算器组件中,我有以下内容。如何检索传入的路径数据?
ngOnInit() {
this.route
.data
.subscribe(v => this.selectedPhysical = <Physical>v);
console.log("phys = " + this.selectedPhysical);
}
&#13;
任何人都知道如何做到这一点?
答案 0 :(得分:1)
您需要将依赖于更新数据的代码移动到subscribe(...)
回调
ngOnInit() {
** problem is here **, I've tried every combination of things and nothing works. Its always undefine.
this.route
.data
.subscribe(v => {
this.selectedPhysical = <Physical>v;
console.log("phys = " + this.selectedPhysical);
});
// don't know about these
this.selectedSex = this.userSettings.sex;
//console.log('route id =' + this.route.snapshot.params.id)
}