在应用路线: 如何恢复从路径角度RC4数据
{ 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);
}
任何人都知道如何做到这一点?
这将是巨大的,如果你不使用片断功能的代码是不可运行。你的大部分问题都由完全无用的鲜艳的按钮组成。改为使用“{}”按钮。 –
只需使用共享服务在组件之间进行通信即可。数据目前仅用于静态添加到路由的数据,路由器提供的所有内容都反映在URL –
好..我刚开始使用这个网站,因为它是唯一获得angular2帮助的地方..我会尝试使用{ }按钮,你想让我重做这个帖子吗?或者你会告诉我我在路由中做错了什么? –