如何从ActivatedRoute(Angular2)获取出口参数
我的路线定义为:如何从ActivatedRoute(Angular2)获取出口参数,angular,typescript,router,outlet,Angular,Typescript,Router,Outlet,我的路线定义为: path: 'geooperations', component: GeoMetricsComponent, children: [ { path: ':idgeooperationmetrictype', component: DetailGeoMetricTypeComponent, outlet: 'geo' }, { path: ':idgeooperationmetrictype/edit', component: De
path: 'geooperations',
component: GeoMetricsComponent,
children: [
{ path: ':idgeooperationmetrictype', component: DetailGeoMetricTypeComponent, outlet: 'geo' },
{ path: ':idgeooperationmetrictype/edit', component: DetailGeoMetricTypeComponent, outlet: 'geo' },
{ path: '/new', component: DetailGeoMetricTypeComponent, outlet: 'geo' }
]
示例:
URL:geooperations/(地理位置:c56da64c-0ef5-4894-83ee-043818b44e14)
如何从ActivatedRoute获取“idgeooperationmetrictype”?您需要在组件“DetailGeoMetricTypeComponent”中订阅它
或者使用开发工具在参数行设置断点以查看键。通过使用快照解决了问题。参数:
this.activatedRoute.snapshot.params.subscribe(params => {
console.log(params['idgeooperationmetrictype']);
});
第一个答案不起作用。但是,我可以通过此.activatedRoute.url.\u值[0].path获取“idgeooperationmetrictype”。我不知道这是否正常,或者是否有其他方法可以通过outlet params执行此操作?
activatedRoute.snapshot.params
完成了此操作。
ngOnInit() {
this.sub = this.route.params.subscribe(params => {
this.id = params['idgeooperationmetrictype'];
});
}
this.activatedRoute.snapshot.params.subscribe(params => {
console.log(params['idgeooperationmetrictype']);
});